【发布时间】: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