使用Python脚本从Windows机器传输文件到远程Solaris机器
我用以下代码来建立我本地电脑和远程电脑之间的连接:
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失败。
有人能帮我解决这个问题吗?
2 个回答
1
如果你用的是22号端口,那你用错端口了,因为大多数系统都是用22号端口来进行SSH连接的。假设22号端口是正常的SSH端口,你应该使用scp或者sftp来传输文件。(如果你用Python,可以试试paramiko这个库)。如果你确定远程服务器是运行FTP的,那就用默认的21号端口。
2
你需要把端口作为一个单独的参数来指定,而不是像你在 remotesite
中那样写。试试这样:
remotesite = '10.88.203.21'
port = 22
connection = ftplib.FTP(remotesite, port)
想了解更多信息,可以查看 FTP 文档。