Where can I find an example that uses FTP standard library?

Grig Gheorghiu grig.gheorghiu at gmail.com
Mon Nov 14 22:06:43 EST 2005


I have some code that looks something like this:

from ftplib import FTP

ftp = FTP()
# connect and login
ftp.connect(server_name)
ftp.login(user_name, password)
cmd = "STOR %s" % filename
#"ASCII transfer"
l = open(filename)
ftp.storlines(cmd, l)
#"BIN transfer"
l = open(filename, 'rb')
ftp.storbinary(cmd, l)
# close connection
ftp.close()

All the various methods on the ftp object should be called in
try/except blocks, since they can potentially raise exceptions.

Grig




More information about the Python-list mailing list