Discussion:
[Tutor] FTP GET from Variables Stored in File
Eric Grey
2015-06-03 16:49:11 UTC
Permalink
I'm fairly new to programming and as a result, Python too. I've been
researching the Tutor archives trying to find a solution to my need,
however, haven't stumbled across the exact example and are now in
information overload. Wondering if I could get some help? I have the need
to perform an FTP GET for specific files in a large directory of files.
There are many examples out there of FTP'ing from a server after doing the
equivalent to a Unix 'ls -la' command and thus, getting all files in the
directory or matching on a pattern (i.e., all files ending with *.txt).

My problem is I don't have files with a clear pattern of association to
allow a pattern match. For example I have 1000 files in a directly with
file names like: apple.txt, blue.txt, car.txt, sky.rtf, etc. I know the
filenames I want, however it could be say 75 of 1000 files I need to issue
a GET on. Inefficient to individually code all 75 explicit file name
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?

Thanks.

//eric
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Alan Gauld
2015-06-03 19:58:45 UTC
Permalink
Post by Eric Grey
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.
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


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Continue reading on narkive:
Loading...