[Tutor] FTP GET from Variables Stored in File

Eric Grey grey.eric at gmail.com
Wed Jun 3 18:49:11 CEST 2015


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


More information about the Tutor mailing list