脚本如下:
-
import sshtunnel
-
from getpass import getpass
-
-
ssh_host=YOUR_SSH_HOST
-
ssh_port=22
-
ssh_user=YOUR_SSH_USER
-
-
REMOTE_HOST=FTP_SERVER
-
REMOTE_PORT=21
-
-
from sshtunnel import SSHTunnelForwarder
-
ssh_password=getpass('Enter your_SSH_PASSWORD:')
-
-
server=SSHTunnelForwarder(
-
ssh_address_or_host=(ssh_host,ssh_port),
-
ssh_username=ssh_user,
-
ssh_password=ssh_password,
-
remote_bind_address=(REMOTE_HOST,REMOTE_PORT))
-
-
server.start()
-
print('Connct the remote service via local port: %s' %server.local_bind_port)
-
#work with ftp service via the server.local_bind_port
-
try:
-
while True:
-
pass
-
except keyboardInterrupt:
-
print('Exiting user request.\n')
-
server.stop()
脚本执行起来以后会在本地有一个端口监听,连接这个端口其实就连上了远程的ftp.
但是我执行ls 有报错。
ftp> ls
227 Entering Passive Mode
ftp: connect: Invalid argument
原因不明
阅读(2644) | 评论(0) | 转发(0) |