Is there an easier-to-use module than ftplib?
Rick Lee
rwklee at home.com
Tue Feb 20 21:09:02 EST 2001
Thanks! That looks simple enough. Do I have to worry about active vs.
passive mode?
Raymond Hettinger wrote:
> Rick Lee wrote:
>
> > Is there an easier-to-use module than ftplib in the standard library,
> > for both uploading and downloading files? I can't use urllib because it
> > does not support uploading, it seems; and I am hoping I don't have to
> > learn FTP itself, which is required somewhat by ftplib.
> >
> > - Rick Lee
>
> I felt frustrated with ftplib.py at first because the documentation
> pre-supposes that you already know the ftp commands.
>
> I made the following quick notes which show an examples that cover
> 95% of what you might want to do with ftp:
>
> from ftplib import *
> f = FTP('ftp.javanet.com','username','password')
> f.retrlines('LIST') # or f.dir() to list the directory
> f.cwd('public_html') # change directory
>
> r = open('random.htm','w')
> f.retrlines('retr random.htm',r.write) # download a text file
> r.close()
>
> r = open('quoter.pyw','rb') # upload a binary file
> f.storbinary('STOR quoter.pyw',r,512)
> r.close()
>
> f.rename('quoter.pyw','q.pyw') # rename a file
> f.delete('q.pyw') # delete a file
>
> f.quit() # terminate the session
>
> Hope these note help,
>
> Raymond
More information about the Python-list
mailing list