Hi everyone. I'm having a little bit of trouble getting a piece of code to work correctly here.

Here is the code.

    filename = "./" + `random.randrange(0,9999999999999999999999999999999999)` + ".txt"
    f = open(filename, 'w')

    f = open(filename,'rb')
    ftp = FTP('ftphost.com')
    ftp.storbinary('STOR `filename`', f )

Everything works as it is supposed to. The variable "filename" is saved in the current directory with the randomly generated name. When the ftp.storbinary command runs, it uploads the information in the file correctly, however, it always saves it with the name, `filename`. This causes it to overwrite itself each time that it uploads.

Basically, how can I get this to upload the file with the file's actual randomly generated name instead of "`filename`". Any advice would be very helpful, using storbinrary would be nice, but another command or even entire module is ok, as long as it solves my problem.

Thanks a lot!!

If that fails try:

a='STOR '+filename
ftp.storbinary(a, f )

Edited 7 Years Ago by need help!: n/a

Thanks for those :)

I ended up fixing the problem by just sending another ftp command.


But thank you for your replies!

This question has already been answered. Start a new discussion instead.