【问题标题】:Python ftplib file-transfer error_permPython ftplib 文件传输 error_perm
【发布时间】:2013-11-18 13:11:59
【问题描述】:

我正在尝试在 python 2.7 中自动化测试(在 linux ubuntu 12.04 上的 eclipse 中),我需要测试 FTP 服务器以下内容: 我必须在主机上创建一个文件,通过 FTP 将其传输到另一台 PC,然后以另一个名称将其传输回我的主机。然后我有两个文件需要比较。我是这样开始的:

    #create the two files
    firstFilename = "first_testfile.txt"
    secondFilename = "second_testfile.txt"
    os.system("echo \"test\" > {0}".format(firstFilename))
    os.system("touch {0}".format(secondFilename))

    #setup FTP connection transfer file to other computer
    ftp = self.setupFTP()
    ftp.set_pasv(True)
    f = open(firstFilename)
    ftp.storbinary("STOR {0} ".format(firstFilename), f)
    f.close
    ftp.quit()
    #setup FTP connection transfer file back to host (other filename)
    ftp = self.setupFTP()
    ftp.set_pasv(True)
    f = open(secondFilename, "wb")
    ftp.retrbinary("RETR {0} ".format(secondFilename), f.write)
    ftp.quit()
    #comparison-part will be implemented later
    firstOutput = os.system("cat {0}".format(firstFilename))
    secondOutput = os.system("cat {0}".format(secondFilename))
    #compare somehow

执行此代码给我以下错误:

ftp.retrbinary("RETR {0} ".format(secondFilename), f.write)
error_perm: 550 second_testfile.txt : No such file or directory

有谁知道我做错了什么?

【问题讨论】:

    标签: python linux file ftp ftplib


    【解决方案1】:

    EDIT&SOLVED:我找到了我的问题,应该是

    ftp.retrbinary("RETR {0} ".format(firstFilename), f.write)
    

    而不是

    ftp.retrbinary("RETR {0} ".format(secondFilename), f.write)
    

    因为我想在 RETR 之后我必须告诉应该如何调用文件(实际上是文件处理程序)而不是如何调用 FTP 上的文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-02
      • 2016-10-14
      • 2021-04-09
      • 2021-07-12
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多