JAVA downloader script

Here is a snippet of what Carl had wrote. What I am trying to do is, is to have the downloads go to a directory on the hard drive and not the desktop.

print "Connecting to %s"%string from ftplib import FTP ftp = FTP(string) print "Connected to %s, Logging in..."%string ftp.login('david','bigbrother') print "Downloading from %s"%string ftp.set_pasv(0) file = open(filename, 'wb') ftp.retrbinary('RETR '+filename,file.write) file.close()

I have read the different Pyton sites and believe the correction lies in the os.path.join but exactly where to put it, that is one I am having trouble with. I have tried:

put 'import os' at the begining of this code, then change the following line from file = open(filename, 'wb') to: file = open(os.path.join('c:\',filename), 'wb')

All I get is errors that usually refer to something fatal then it stops the code. another option I found was something like cwd, tried putting that in at various places and it did not function. I am sure it is something really easy and stupid I just can not wrap my head around it and find the solution.

Thanks :prayer:

I’m confused - where is the variable “filename” defined in that script?

The file name is stated elsewhere in the script. I think it is like 2 lines above the snippet I posted. I did not want to post the whole thing because it is somewhat lengthy. If you need it to let me know where to place the code so that the files downloaded go to a specific directory and not the desktop I will post it.

Right now when the script is run all the files downloaded go to the desktop. I want them to go to a directory specified by me.

Oh, I just thought the filename might have come from an fpmi.file.saveFile() call, in which case it would have a full path. If it is just a simple filename like “myfile.txt” then you just need to give it a folder, like:

file = open('C:\\myfolder\\' + filename, 'wb')

Ok maybe it was my typo error I am not sure. While I was researching I saw on some python pages that there was two \ and in other cases it was just one . I noticed by your reply there is two. Is that what there is suppose to be?

If so that might have been my problem because I thought someone made a mistake on the internet and since some pages had 1, I only used one.

quote=“Carl.Gould”]Oh, I just thought the filename might have come from an fpmi.file.saveFile() call, in which case it would have a full path. If it is just a simple filename like “myfile.txt” then you just need to give it a folder, like:

file = open('C:\\myfolder\\' + filename, 'wb')

Well, windows paths are like:

C:\folder\subfolder\file.txt

but if you put that in a python string, it wouldn’t work because backslash is the escape character, so to actually get a backslash you need two of them - one to escape the other.

See docs.python.org/reference/lexica … g-literals