An FTP Client...My first real program!
Python Nutter
pythonnutter at gmail.com
Wed Aug 13 23:51:43 EDT 2008
ery low level and not very useful for beginners as a lot of the heavy
lifting and management is still left up to you, the programmer.
The module ftputil is a high-level interface to the ftplib module. The
FTPHost objects generated from it allow many operations similar to
those of os and os.path. An example:
# download some files from the login directory
host = ftputil.FTPHost('ftp.domain.com', 'user', 'secret')
names = host.listdir(host.curdir)
for name in names:
if host.path.isfile(name):
host.download(name, name, 'b') # remote, local, binary mode
# make a new directory and copy a remote file into it
host.mkdir('newdir')
source = host.file('index.html', 'r') # file-like object
target = host.file('newdir/index.html', 'w') # file-like object
host.copyfileobj(source, target) # similar to shutil.copyfileobj
source.close()
target.close()
Now if you are again purely in it for a challenge or for and
educational roller coaster ride, ignore the suggestion to look at
higher level ftp modules =)
Cheers,
PN
More information about the Python-list
mailing list