Python ftplib文件传输错误\u perm

Python ftplib文件传输错误\u perm,python,linux,file,ftp,ftplib,Python,Linux,File,Ftp,Ftplib,我正在尝试用python 2.7(在linux ubuntu 12.04上的eclipse中)自动化一个测试,我需要测试FTP服务器,如下所示: 我必须在主机上创建一个文件,通过FTP将其传输到另一台pc,然后用另一个名称将其传输回主机。然后我有两个文件要比较。我是这样开始的: #create the two files firstFilename = "first_testfile.txt" secondFilename = "second_testfile.txt"

我正在尝试用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

有人知道我做错了什么吗?

编辑并解决:我发现了我的问题,应该是

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

ftp.retrbinary("RETR {0} ".format(secondFilename), f.write)
因为我认为在RETR之后,我必须告诉应该如何调用文件(实际上是filehandler),而不是如何调用FTP上的文件