FTP没有在PC上运行

时间:2016-03-29 06:23:35

标签: python ubuntu ftplib

我正在尝试这个FTP文件传输代码。问题是,当我在在线环境(我在Cloud 9上创建的工作区)上运行此代码时,它工作正常并上传了文件但是当我在PC上运行时,我得到了一个错误。我该如何解决?

from ftplib import FTP

ftp=FTP('**domain**')
ftp.login(user='username',passwd='password')
ftp.cwd('/')

def grabFile():
    filename='fileName.txt'
    localfile=open(filename, 'wb')
    ftp.retrbinary('RETR '+filename, localfile.write, 1024)
    ftp.quit()
    localfile.close()

def placeFile():
    filename= 'Strinzy.txt'
    ftp.storbinary('STOR '+filename, open(filename,'rb'))
    ftp.quit()

placeFile()

ERROR:

Traceback (most recent call last):
  File "ftp_trial.py", line 19, in <module>
    placeFile()
  File "ftp_trial.py", line 16, in placeFile
    ftp.storbinary('STOR '+filename, open(filename,'rb'))
  File "/usr/lib/python2.7/ftplib.py", line 468, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "/usr/lib/python2.7/ftplib.py", line 373, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "/usr/lib/python2.7/ftplib.py", line 332, in ntransfercmd
    conn = socket.create_connection((host, port), self.timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 113] No route to host

1 个答案:

答案 0 :(得分:-1)

如果您使用的是vsftpd,请确保您的vsftpd服务在您的计算机上运行,​​并且 /etc/vsftpd.userlist 中包含用户名