if verboseprint('uploading'filelocal open(file'rb'local file of same name remote ftplib ftp(siteconnect to ftp site remote login(*useranonymous or real login remote cwd(dirremote storbinary('stor filelocal remote quit(local close(if verboseprint('upload done 'if __name__ ='__main__'site 'ftp rmi netdir import sysgetpass pswd getpass getpass(site pswd?'putfile(sys argv[ ]sitediruser=('lutz'pswd)filename on cmdline nonanonymous login notice that for portabilitythe local file is opened in rb binary input mode this time to suppress automatic line-feed character conversions if this is binary informationwe don' want any bytes that happen to have the value of the \ carriage-return character to mysteriously go away during the transfer when run on windows client we also want to suppress unicode encodings for nontext filesand we want reads to produce the bytes strings expected by the storbinary upload operation (more on input file modes laterthis script uploads file you name on the command line as self-testbut you will normally pass in real remote filenamesite nameand directory name strings also like the download utilityyou may pass (usernamepasswordtuple to the user argument to trigger nonanonymous ftp mode (anonymous ftp is the defaultplaying the monty python theme song it' time for bit of fun to testlet' use these scripts to transfer copy of the monty python theme song audio file have at my website firstlet' write module that downloads and plays the sample fileas shown in example - example - pp \internet\ftp\sousa py #!/usr/local/bin/python ""usagesousa py fetch and play the monty python theme song this will not work on your system as isit requires machine with internet access and an ftp server account you can accessand uses audio filters on unix and your au player on windows configure this and playfile py as needed for your platform ""from getpass import getpass from pp internet ftp getfile import getfile from pp system media playfile import playfile file 'sousa audefault file coordinates transferring files with ftplib