6 Years
Discussion Span
Last Post by pyTony

First hit from google brought this code

# ftptest.py - An example application using Python's ftplib module.
# Author: Matt Croydon <matt@ooiio.com>, referencing many sources, including:
#   Pydoc for ftplib: http://web.pydoc.org/2.2/ftplib.html
#   ftplib module docs: http://www.python.org/doc/current/lib/module-ftplib.html
#   Python Tutorial: http://www.python.org/doc/current/tut/tut.html
# License: GNU GPL.  The software is free, don't sue me.
# This was written under Python 2.2, though it should work with Python 2.x and greater.

# Import the FTP object from ftplib
from ftplib import FTP

# This will handle the data being downloaded
# It will be explained shortly
def handleDownload(block):
    print ".",
# Create an instance of the FTP object
# Optionally, you could specify username and password:
# FTP('hostname', 'username', 'password')
ftp = FTP('ftp.cdrom.com')

print 'Welcome to Matt\'s ftplib example'
# Log in to the server
print 'Logging in.'
# You can specify username and password here if you like:
# ftp.login('username', 'password')
# Otherwise, it defaults to Anonymous
print ftp.login()

# This is the directory that we want to go to
directory = 'pub/simtelnet/trumpet/winsock'
# Let's change to that directory.  You kids might call these 'folders'
print 'Changing to ' + directory

# Print the contents of the directory

# Here's a file for us to play with.  Remember Trumpet Winsock?
filename = 'twsk30d.exe'

# Open the file for writing in binary mode
print 'Opening local file ' + filename
file = open(filename, 'wb')

# Download the file a chunk at a time
# Each chunk is sent to handleDownload
# We append the chunk to the file and then print a '.' for progress
# RETR is an FTP command
print 'Getting ' + filename
ftp.retrbinary('RETR ' + filename, handleDownload)

# Clean up time
print 'Closing file ' + filename

print 'Closing FTP connection'
print ftp.close()

Then there is the manual http://docs.python.org/library/ftplib.html

This point looks promissing for your MGET

FTP.transfercmd(cmd[, rest])

Initiate a transfer over the data connection. If the transfer is active, send a EPRT or PORT command and the transfer command specified by cmd, and accept the connection. If the server is passive, send a EPSV or PASV command, connect to it, and start the transfer command. Either way, return the socket for the connection.

If optional rest is given, a REST command is sent to the server, passing rest as an argument. rest is usually a byte offset into the requested file, telling the server to restart sending the file’s bytes at the requested offset, skipping over the initial bytes. Note however that RFC 959 requires only that rest be a string containing characters in the printable range from ASCII code 33 to ASCII code 126. The transfercmd() method, therefore, converts rest to a string, but no check is performed on the string’s contents. If the server does not recognize the REST command, an error_reply exception will be raised. If this happens, simply call transfercmd() without a rest argument.

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.