我真的很难获得一个简单的.txt
文件上传到FTP服务器。我的桌面上有一个文件夹,其中包含两个文件:text.txt
和upload_to_ftp.py
。
我试过这些:
FTP file upload
Python Script Uploading files via FTP
但似乎都不起作用。
我已经重复编写了这么多次代码,并且不断出现错误,例如:
sftp = ftplib.FTP('REMOTEFTPSITE.com', 'MYUSERNAME', 'MYPASSWORD')
File "C:\Python27\lib\ftplib.py", line 117, in __init__
self.connect(host)
File "C:\Python27\lib\ftplib.py", line 135, in connect
self.welcome = self.getresp()
File "C:\Python27\lib\ftplib.py", line 210, in getresp
resp = self.getmultiline()
File "C:\Python27\lib\ftplib.py", line 196, in getmultiline
line = self.getline()
File "C:\Python27\lib\ftplib.py", line 183, in getline
line = self.file.readline()
File "C:\Python27\lib\socket.py", line 447, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10054] An existing connection was forcibly closed by the remote host
任何帮助都会很棒!提前谢谢。
答案 0 :(得分:0)
确保您确实在此行中提供了服务器,用户名和密码:
sftp = ftplib.FTP('REMOTEFTPSITE.com', 'MYUSERNAME', 'MYPASSWORD')