!/usr/local/bin/python
import ftplib # socket-based FTP tools
def putfile(file, site, dir, user=(), , verbose=True): """ store a file by ftp to a site/directory anonymous or real login, binary transfer """ if verbose: print('Uploading', file) local = open(file, 'rb') # local file of same name remote = ftplib.FTP(site) # connect to FTP site remote.login(user) # anonymous or real login remote.cwd(dir) remote.storbinary('STOR ' file, local, 1024) remote.quit() local.close() if verbose: print('Upload done.')
if name == 'main': site = 'ftp.rmi.net' dir = '.' import sys, getpass pswd = getpass.getpass(site ' pswd?') # filename on cmdline putfile(sys.argv[1], site, dir, user=('lutz', pswd)) # nonanonymous login
---------------------------------------------------putfilegui.py from tkinter import mainloop import putfile, getfilegui
class FtpPutfileForm(getfilegui.FtpForm): title = 'FtpPutfileGui' mode = 'Upload' def do_transfer(self, filename, servername, remotedir, userinfo): putfile.putfile(filename, servername, remotedir, userinfo, verbose=False)
if name == 'main': FtpPutfileForm() mainloop()