我使用以下代码在本地计算机和远程计算机之间建立连接:
import os, sys, ftplib
nonpassive=False
remotesite= '10.88.203.21:22'
remoteuser='root'
remotepass='v-peg8!@#'
localdir= "c:\\.."
print "connecting"
connection=ftplib.FTP(remotesite)
print "successfully connected"
connection.login(remoteuser,remotepass)
if nonpassive:
connection.set_pasv(False)
但它给了我以下错误: socket.gaierror:[Errno 11001] getaddrinfo失败.. 有人可以帮助我解决这个问题。
答案 0 :(得分:2)
您需要将端口指定为单独的参数,而不是remotesite
中的方式。尝试:
remotesite = '10.88.203.21'
port = 22
connection = ftplib.FTP(remotesite, port)
有关详细信息,请参阅FTP docs。
答案 1 :(得分:1)
如果它的端口22,那么你使用了错误的端口,因为大多数系统使用22用于SSH协议。假设22是正常的SSH端口,你应该使用scp / sftp。 (试试Python的paramiko)。如果您确定远程服务器正在运行FTP,请使用默认端口21。