Automating FTP file transfers

Batista, Facundo FBatista at uniFON.com.ar
Wed Nov 12 08:56:39 EST 2003


Limey Drink wrote:

#- Basically I need to...
#- 1.  Check on the local system for new files in a specific directory
#- If new files exist then...
#- 2.  Connect to a remote FTP server.
#- 3.  Transfer local files to a specific directory on the 
#- remote FTP server.
#- 4.  Then remove/archive local files and end session.

Little piece of code that automates FTP, putting files whose names were
passed as args:

import sys
from ftplib import FTP

lnomarch = sys.argv[1:]
dir = '/local/BACKUP/logs'
machine = 'masbue'
transported = []

print "Opening conection"
ftp = FTP(machine)
ftp.login('myUsername', 'myPassword')
ftp.cwd(dir)
for nomarch in lnomarch:
        print "Putting", nomarch
        arch = open(nomarch, 'r')
        nombrebase = os.path.basename(nomarch)
        transported.append(nombrebase)
        ftp.storbinary('STOR ' + nombrebase, arch)
        arch.close()
ftp.quit


.	Facundo





More information about the Python-list mailing list