如何通过ftp在服务器上上传压缩文件 [英] how to upload ziped file on server via ftp
本文介绍了如何通过ftp在服务器上上传压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在python中有此代码,可通过ftp在服务器上上传photos.zip文件.
i have this code in python for upload photos.zip file on the server via ftp.
import ftplib
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD')
file = open('c:\archived\photos.zip','rb') # file to send
session.storbinary('STOR photos.zip', file) # send the file
file.close() # close file and FTP
session.quit()
但是我有这个错误: T
but i have this error : T
raceback (most recent call last):
File "a.py", line 24, in <module>
file = open('c:\archived\photos.zip','rb')
IOError: [Errno 22] invalid mode ('rb') or filename: 'c:\archived\photos.zip'
我也使用了此解决方案:
also I used this solution :
file = open(os.path.join('c:/','archived','photos.zip'),'rb')
但是我得到这个错误:
Traceback (most recent call last):
File "s.py", line 28, in <module>
session.storbinary('s.zip', file)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 479, in storbinary
conn = self.transfercmd(cmd, rest)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 378, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 341, in ntransfercmd
resp = self.sendcmd(cmd)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 251, in sendcmd
return self.getresp()
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 226, in getresp
raise error_perm, resp
ftplib.error_perm: 500 Unknown command.
推荐答案
使用被认为更好的os.path.join
.
file = open(os.path.join('c:/','archived','photos.zip'),'rb')
如果要坚持使用字符串,请使用\\
而不是\
.
If you want to stick to your string, use \\
instead of \
.
这篇关于如何通过ftp在服务器上上传压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文