报错内容:
*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
- #-*- coding: utf-8 -*-
- from ftplib import FTP
- def ftpconnect():
- ftp_server = '10.***.***.**' #FTP server ip address
- username = 'tom'
- password = '*******'
- timeout =30
- port = 21
- ftp=FTP()
- ftp.set_debuglevel(2) #open debug level 2, can display detail message
- ftp.connect(ftp_server,port,timeout) #connect to FTP server
- ftp.login(username,password)
- return ftp
- def downloadfile_from_FTP():
- ftp = ftpconnect()
- print ftp.getwelcome() #can display FTP server welcome message.
- bufsize = 1024 #set buffer size
- remotepath = "\\Home\\product\\tom\\win7.iso"
- localpath = 'D:\\tom\\win7.iso'
- fp = open(localpath,"wb")
- ftp.retrbinary('RETR %s' % remotepath,fp.write,bufsize) #start to download file :FTP server --> local
- ftp.set_debuglevel(0) # close debug
- fp.close() #close connect
- ftp.quit() #quit FTP server
- def uploadfile_to_FTP():
- ftp = ftpconnect()
- print ftp.getwelcome() #can display FTP server welcome message.
- bufsize = 1024
- remotepath = "\\Home\\product\\tom\\win8.iso"
- localpath = 'D:\\system\\win8.iso'
- fp = open(localpath,'rb')
- ftp.storbinary('STOR '+ remotepath ,fp,bufsize) #start to upload file :local --> FTP server
- ftp.set_debuglevel(0) # close debug
- fp.close() #close connect
- ftp.quit() #quit FTP server
- if __name__ == "__main__":
- #downloadfile_from_FTP()
- uploadfile_to_FTP()