我需要创建简单的代码,将.csv文件上传到FTP服务器。代码如下。
import ftplib
import os
import sys
sourceFilePath = '/home/user/dir/'
filename = 'testing.csv'
destinationDirectory = 'anotherDirectory'
server = 'ftp://12.123.12.234'
username = 'aUser'
password = 'passwd1234'
myFTP = ftplib.FTP(server, username, password)
myFTP.cwd('/anotherDirectory/')
myFTP.storbinary('STOR '+filename, open(filename,'rb'))
myFTP.quit()
但是,当我运行代码时,我收到以下错误:
Traceback (most recent call last):
File "./UploadToFTP.py", line 20, in <module>
File "./UploadToFTP.py", line 13, in uploadFileFTP
myFTP = ftplib.FTP(server, username, password)
File "/usr/lib64/python2.6/ftplib.py", line 119, in __init__
self.connect(host)
File "/usr/lib64/python2.6/ftplib.py", line 134, in connect
self.sock = socket.create_connection((self.host, self.port),
self.timeout)
File "/usr/lib64/python2.6/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -3] Temporary failure in name resolution
有没有人见过这个?这对我来说似乎很通用,并没有告诉我太多。至于其他代码我见过执行同样的任务,我没有任何当前可见的错误。任何帮助将不胜感激。
答案 0 :(得分:1)
host
构造函数的ftplib.FTP
参数是主机名/ IP地址,而不是URL。
所以这是错误的:
server = 'ftp://12.123.12.234'
应该是:
server = '12.123.12.234'