Posts Tagged ‘snippet’

Python Code Snippet: Send a file to an FTP server

Monday, June 22nd, 2009

Here is a snippet of code I put together to take a file and upload it via FTP to a remote site.

import ftplib
# connect to the server
ftpsite = ftplib.FTP('','FTPUSER','FTPPASSWD')
file = open('FileName.txt','rb')                # file to send
ftpsite.storbinary('STOR FileName.txt', file)   # send the file
file.close()                                    # close file and FTP

There are a crapload of similar code snippets available here: Seb Sauvage’s Python Snyppets. Thanks for putting all of these online, Seb!