Skip to content

Instantly share code, notes, and snippets.

@icecreammatt
Created April 30, 2015 00:17
Show Gist options
  • Select an option

  • Save icecreammatt/3ccf05a8c6c4d3f1ca30 to your computer and use it in GitHub Desktop.

Select an option

Save icecreammatt/3ccf05a8c6c4d3f1ca30 to your computer and use it in GitHub Desktop.
from ftplib import FTP
# Server connection string
remoteUrl = 'ftp.debian.org'
ftp = FTP(remoteUrl)
# Login
ftp.login()
# Switch to folder
ftp.cwd('debian')
# List contents
ftp.dir()
# Upload file - Untested!
# http://stackoverflow.com/a/17438193/873559
fileName = 'filename.txt'
fileNameBinary = 'filename.bin'
myFile = open(fileName, 'r')
myFileBinary = open(fileNameBinary, 'rb')
ftp.storbinary("RETR " + 'filename.txt', myFile)
ftp.storlines("STOR " + 'filename.txt', myFileBinary)
myFile.close()
myFileBinary.close()
ftp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment