Skip to content

Instantly share code, notes, and snippets.

@ironpythonbot
Created December 9, 2014 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironpythonbot/687973e8ceb85027f8b9 to your computer and use it in GitHub Desktop.
Save ironpythonbot/687973e8ceb85027f8b9 to your computer and use it in GitHub Desktop.
CodePlex Issue #32770 Plain Text Attachments
import ftplib
import os
import sys
import traceback
import socket
socket.settimeout(20.0)
print "Logging in..."
ftp = ftplib.FTP()
host = "...."
port = 21
login = "..."
password = "..."
some_directory = "/"
fullname = "test.txt"
ftp.connect(host, port)
print ftp.getwelcome()
try:
try:
ftp.login(login, password)
ftp.cwd(some_directory)
ftp.set_pasv(True)
# move to the desired upload directory
print "Currently in:", ftp.pwd()
name = os.path.split(fullname)[1]
print "Uploading...", name
f = open(fullname, "rb")
ftp.storbinary('STOR ' + name, f)
f.close()
print "OK"
print "Files:"
print ftp.retrlines('LIST')
finally:
print "Quitting..."
ftp.quit()
except:
traceback.print_exc()
raw_input("Press Enter...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment