954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

FTP upload problem

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!!

Insomaniacal
Newbie Poster
6 posts since Dec 2009
Reputation Points: 10
Solved Threads: 1
 
a="STOR '"+filename+"'"
ftp.storbinary(a, f )
need help!
Newbie Poster
12 posts since Dec 2009
Reputation Points: 10
Solved Threads: 3
 

If that fails try:

a='STOR '+filename
ftp.storbinary(a, f )
need help!
Newbie Poster
12 posts since Dec 2009
Reputation Points: 10
Solved Threads: 3
 

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!

Insomaniacal
Newbie Poster
6 posts since Dec 2009
Reputation Points: 10
Solved Threads: 1
 
jintujacob
Newbie Poster
4 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: