Skip to content

Instantly share code, notes, and snippets.

@gferreira
Created July 12, 2011 00:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gferreira/1077087 to your computer and use it in GitHub Desktop.
Save gferreira/1077087 to your computer and use it in GitHub Desktop.
upload file to server via ftp
import os
from ftplib import FTP
def connectToServer(url, login, password, folder, verbose=False):
# create FTP connection
ftp = FTP(url, login, password)
if verbose == True:
print "%s" % ftp.getwelcome()
# move to folder
ftp.cwd(folder)
if verbose == True:
ftp.retrlines('LIST')
print
return ftp
def uploadFile(filePath, FTPconnection):
file = open(filePath, 'rb')
fileName = os.path.split(filePath)[1]
FTPconnection.storbinary('STOR ' + fileName, file)
file.close()
# FTP and file settings
FTP_URL = 'server1.myserver.com'
FTP_folder = 'www/mysite/fonts'
FTP_login = 'username'
FTP_password = 'XXXXXX'
myFile = '/Users/me/fonts/MyFont.otf'
# create FTP connection
F = connectToServer(FTP_URL, FTP_login, FTP_password, FTP_folder, verbose=True)
# upload file
uploadFile(myFile, F)
# close connection
F.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment