newbie needs a little help... trying to write an ftp script.

google account mynews44 at yahoo.com
Tue Jul 29 14:35:35 EDT 2003


Wojtek Walczak posted a simple example:

<snipped my original post>> 

> import ftplib,sys
> 
> ftp = ftplib.FTP('ftp.python.org')
> ftp.login('anonymous','qwe at asd.pl')
> print ftp.retrlines('LIST')

I think it works the same if I use print or simply
ftp.retrlines('list')


> ftp.cwd('pub/python')
> print ftp.retrlines('LIST')


I am interested in reading this into a string so that I can process
it.  I need to get the name of each file in teh directory so that I
can do a loop to retr them all; ie,  strip out all directories,  and
then strip out all the extra information (permissions, dates.  I try
stuff like

SomeString = ftp.retrlines('list')

but this only seems to read in the return string:

print SomeString
226 Transfer Complete

IS there anyway I can read in the whole thing?   It is obviously
taking the string as being the only part between the single quotes... 
I don't know how to read the rest into a string.



> print ftp.retrbinary('retr README', sys.stdout.write)

This is the line I am most interested in!  I assume that the callback
has something to do with how the program handles the data it is
retrieving,  and that to save the file it is retrieving I have to open
a file,  write the file,  then close the file...  This line would be
the writing of the file,  I am guessing.  something like

filename = open(r'd:\downloads\' + file, 'w')
ftp.retrbinary('retr README', filename)
filename.close

And that I can run this thing through a loop for each of the filenames
that I get outta the first string.


Am I completely way offbase here with what I am attempting?  Is this
going to actually download the files from the ftp server to the local
hardware?  Once I can read the output into a string I guess I can get
kicked off.  This is my current hurdle.


Thanks for looking!  

googleboy.




More information about the Python-list mailing list