Created
July 12, 2011 00:05
-
-
Save gferreira/1077087 to your computer and use it in GitHub Desktop.
upload file to server via ftp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
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