Help implementing an idea

rh0dium sklass at pointcircle.com
Fri Jun 17 19:32:27 CEST 2005


Try this..


#!/usr/bin/env python
# Upload a file to a FTP server

from sys import argv, exit
from ftplib import FTP

if len(argv) != 6:
     print 'Incorrect number of parameters'
     print 'USAGE: upload.py <server> <username> <password> <local
file>
<remote file>'
     exit(0)

server = argv[1]
username = argv[2]
password = argv[3]
upfile = argv[5]
downfile = argv[4]

try:
     print 'Connecting to %s' % server
     ftp = FTP(server)
     ftp.login(username, password)
     print 'Connection to %s opened' % server
     #send file in binary mode to server (STOR command sets remote
filename)
     ftp.storbinary('STOR %s' % upfile, open(downfile,'r'))
     ftp.quit()
     print 'File %s uploaded' % upfile
except Exception, err:
     print 'Error uploading file. Error: %s' % err




More information about the Python-list mailing list