使用ftp在python中传输文件

时间:2017-02-07 10:58:55

标签: python

python新手。我正在尝试使用相同IP的FTP在python中传输文件,这是程序。

import os
import ftplib
import sys

            ftp = ftplib.FTP(ipaddress)
            ftp.login(username = user,passwd = password)
            ext = os.path.splitext(filename)[1]
            if ext in (".txt"):
                ftp.cwd(filepathDestination)
                ftp.storlines("STOR " + filename, open(filename))
            else:
                ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024)
        else:
            print 'Wrong IP'

,它显示的错误是:

Traceback (most recent call last):
  File "ftp.py", line 35, in <module>
    ftp = ftplib.FTP(ipaddress)
  File "/usr/lib64/python2.6/ftplib.py", line 116, in __init__
    self.connect(host)
  File "/usr/lib64/python2.6/ftplib.py", line 131, in connect
    self.sock = socket.create_connection((self.host, self.port), self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
    raise error, msg
socket.error: [Errno 111] Connection refused

0 个答案:

没有答案