代码之家  ›  专栏  ›  技术社区  ›  Nastyjoe

二进制中的FTPlib错误

  •  1
  • Nastyjoe  · 技术社区  · 7 年前

    我在线路上出错 ftp.retrbinary(“RETR”+文件名,localfile.write) ftplib。error\u perm:500未知命令 . 索蒙能帮我解决这个问题吗?

    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()
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   taras    7 年前

    只需在RETR后添加一个空格,这是一个更新版本。

    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()
    
        2
  •  1
  •   Dimitris Fasarakis Hilliard    7 年前

    'RETR' 文件名表示您正在发送单个命令: 'RETRscxmlsoap.log' . 当然,这并不是 'RERT'

    只需在它们之间添加一个空格: 'RERT {}'.format(filename)