报错内容:
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Switching to Binary mode.\r\n'
*resp* '200 Switching to Binary mode.'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (10,65,252,38,254,125).\r\n'
*resp* '227 Entering Passive Mode (10,65,252,38,254,125).'
*cmd* 'STOR DODWAL0103920180507010001.AVL'
*put* 'STOR DODWAL0103920180507010001.AVL\r\n'
*get* '553 Could not create file.\r\n'
*resp* '553 Could not create file.'
553 Could not create file.
错误原因: 远程路径没有权限
ftp = ftpconnect("ip地址", "用户名", "密码",'远程路径')
下面为借鉴代码:源地址:https://blog.csdn.net/dingqingsong/article/details/44243651
-
- from ftplib import FTP
-
-
- def ftpconnect():
- ftp_server = '10.***.***.**'
- username = 'tom'
- password = '*******'
- timeout =30
- port = 21
-
- ftp=FTP()
- ftp.set_debuglevel(2)
- ftp.connect(ftp_server,port,timeout)
- ftp.login(username,password)
-
- return ftp
-
- def downloadfile_from_FTP():
- ftp = ftpconnect()
- print ftp.getwelcome()
-
- bufsize = 1024
-
- remotepath = "\\Home\\product\\tom\\win7.iso"
- localpath = 'D:\\tom\\win7.iso'
-
- fp = open(localpath,"wb")
- ftp.retrbinary('RETR %s' % remotepath,fp.write,bufsize)
-
- ftp.set_debuglevel(0)
-
- fp.close()
-
- ftp.quit()
-
-
- def uploadfile_to_FTP():
- ftp = ftpconnect()
- print ftp.getwelcome()
-
- bufsize = 1024
- remotepath = "\\Home\\product\\tom\\win8.iso"
- localpath = 'D:\\system\\win8.iso'
-
- fp = open(localpath,'rb')
-
- ftp.storbinary('STOR '+ remotepath ,fp,bufsize)
- ftp.set_debuglevel(0)
-
- fp.close()
-
- ftp.quit()
-
-
- if __name__ == "__main__":
-
- uploadfile_to_FTP()