#!/usr/bin/python # Upload a file via FTP # usage: ftpup.py host/path/filename [user password] from ftplib import FTP import string, sys # parse the first argument: argc= len(sys.argv)- 1 arg1= sys.argv[1] if arg1[:4] == 'ftp:' : arg1= arg1[4:] i= string.find(arg1, '/') if i>= 0 : host= arg1[:i] filename= arg1[i+1:] else : host= arg1 filename= 'index.html' # parse username and password: user='anonymous' passwd='1@2.3' if argc>= 3 : user= sys.argv[2] passwd= sys.argv[3] print "Host: "+ host+ " Filename: "+ filename+ " User: "+ user # here we go: ftp = FTP(host) ftp.login(user, passwd) input= open(filename, 'r') ftp.storbinary("STOR "+filename, input) input.close() ftp.quit()