0

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.write(`data`)
    f.close

    f = open(filename,'rb')
    ftp = FTP('ftphost.com')
    time.sleep(5)
    ftp.login('user,pass')
    time.sleep(5)
    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!!

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by jintujacob
0

If that fails try:

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

Edited by need help!: n/a

0

Thanks for those :)

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

ftp.rename("`filename`",filename)

But thank you for your replies!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.