Question

I'm trying to automate a test in python 2.7 (in eclipse on linux ubuntu 12.04) and I need to test the FTP server the following: I have to create a file on a host, transfer it per FTP to another pc, and then transfer it back to my host under another name. Then I've got two files which I have to compare. I started like this:

    #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

Executing this code gives me the following error:

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

Does anyone know what I did wrong?

Was it helpful?

Solution

EDIT&SOLVED: I've found my problem, it should be

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

instead of

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

since I thought after RETR I have to tell how the file should be called (actually the filehandler is for that) instead of how the file on the FTP is called.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top