[Tutor] FTP GET from Variables Stored in File

Alan Gauld alan.gauld at btinternet.com
Wed Jun 3 21:58:45 CEST 2015


On 03/06/15 17:49, Eric Grey wrote:

> declarations in a script.  So I have the name of each file (i.e.,
> apple.txt, blue.txt) in a separate "seed file" that I want the script to
> read in and treat each line of the "seed file" as the variable I want to
> request the FTP GET on.
>
> So something like:
> seedfile.txt contents = apple.com, blue.com. car.txt
> Open FTP
> CD
> Read "seedfile.txt"
> For each line in "seedfile.txt" use the line as the variable and issue FTP
> GET on that variable
> Repeat till end of "sendfile.txt"
> quit.
>
> Thoughts?  Help?

Yes that looks like a sensible approach and is almost Python.
What bits of it are you struggling with? Convert your pseudo
code into Python code and show us what breaks. Let me do one
step towards that for you...

Open FTP
FTP.CD
with open("seedfile.txt") as filenames:
     for name in filenames:
         FTP.GET(name.strip())
Close FTP

Can you fill in the blanks?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list