newbie needs a little help... trying to write an ftp script.
mynews44 at yahoo.com
Tue Jul 29 10:01:03 CEST 2003
> Googleboy wrote:
> > import ftplib
> > ftp = ftplib.FTP('172.30.30.30') # This is wrong, somehow...?
> > ftp.login(user,pass)
> > ftp.retrlines('LIST') # I believe it might need to be
> > ftp.retrlines('ls -al')
> > ftp.sendcmd('prompt')
> > ftp.cwd('folder')
> > ftp.retrbinary(retr *tgz)
> > ftp.quit()
> Your example worked fine with me for "ftp.suse.com" - at least the first 3
> lines. It didn't understand ls -al and prompt, and a folder "folder" didn't
> exist of course.
A bit of further reading pointed out to me that sendcmd is limited to
rfc959 commands only, it doens't interpret commands you can type into
an ftp session as I first assumed. So things like "prompt' (which
turns interactive mode off in ftp clients) won't work.
This introduces extra complexity to my task - I am trying to log into
an ftp site and do a "mget *tgz" and have it download all files ending
in tgz. I don't think this is a simple thing to accomplish anymore.
> The ftp.retrbinary(retr *tgz) is also flawed - what is retr, a variable? I
> think you need to look up that command again. And *tgz can't be right, too.
> You most probably want "*tgz" there (a string literal)
I think I wanted the whole thing to be a string literal. I have done
a bit more poking and prodding and found that
will work, so long as file is a text document, so it can spit the
output to standard out.
retrlines/retrbinary has this thing called a callback. I am expecting
that is something that allows the script to write the file. I also
imagine that it will only allow me to have one open callback at a
time. This further complicates achieving my objectives.
I think I am going to have to figure out some sort of a for loop based
on the output of a list command.
thanks for the help diez.
More information about the Python-list