retrbinary 中的 FTPlib 错误
FTPlib error in retrbinary
我在行 "ftp.retrbinary("RETR" + 文件名,localfile.write)" 中遇到错误。它并没有说我只是得到 ftplib.error_perm:500 unknown command 到底出了什么问题。 somoen可以帮我解决这个问题吗?
from ftplib import FTP
def grabfile ():
if not os.path.exists(dtt):
os.makedirs(dtt)
ftp = FTP('IP')
ftp.login(user="ftpread", passwd = 'PSW')
ftp.cwd("/var/log/")
filename = "scxmlsoap.log"
#localfilename = "scxmlsoap.log"
localfile = open(filename, "wb")
ftp.retrbinary("RETR" + filename, localfile.write)
ftp.quit()
localfile.close()
f.close()
def main():
grabfile()
main()
RETR后面加个space就可以了,这里是更新的版本
ftp = FTP('IP')
ftp.login(user="ftpread", passwd = 'PSW')
ftp.cwd("/var/log/")
filename = "scxmlsoap.log"
#localfilename = "scxmlsoap.log"
localfile = open(filename, "wb")
ftp.retrbinary("RETR %s" % filename, localfile.write) # <-- a space added
ftp.quit()
localfile.close()
f.close()
在 'RETR'
和文件名之间没有 space 这一事实意味着您正在发送一个命令:'RETRscxmlsoap.log'
。当然,这不会被解释为您需要的 'RERT'
命令。
在它们之间加一个space即可:'RERT {}'.format(filename)
.
我在行 "ftp.retrbinary("RETR" + 文件名,localfile.write)" 中遇到错误。它并没有说我只是得到 ftplib.error_perm:500 unknown command 到底出了什么问题。 somoen可以帮我解决这个问题吗?
from ftplib import FTP
def grabfile ():
if not os.path.exists(dtt):
os.makedirs(dtt)
ftp = FTP('IP')
ftp.login(user="ftpread", passwd = 'PSW')
ftp.cwd("/var/log/")
filename = "scxmlsoap.log"
#localfilename = "scxmlsoap.log"
localfile = open(filename, "wb")
ftp.retrbinary("RETR" + filename, localfile.write)
ftp.quit()
localfile.close()
f.close()
def main():
grabfile()
main()
RETR后面加个space就可以了,这里是更新的版本
ftp = FTP('IP')
ftp.login(user="ftpread", passwd = 'PSW')
ftp.cwd("/var/log/")
filename = "scxmlsoap.log"
#localfilename = "scxmlsoap.log"
localfile = open(filename, "wb")
ftp.retrbinary("RETR %s" % filename, localfile.write) # <-- a space added
ftp.quit()
localfile.close()
f.close()
在 'RETR'
和文件名之间没有 space 这一事实意味着您正在发送一个命令:'RETRscxmlsoap.log'
。当然,这不会被解释为您需要的 'RERT'
命令。
在它们之间加一个space即可:'RERT {}'.format(filename)
.