Skip to content

Instantly share code, notes, and snippets.

@Nemolog
Created March 1, 2009 21:22
Show Gist options
  • Save Nemolog/72475 to your computer and use it in GitHub Desktop.
Save Nemolog/72475 to your computer and use it in GitHub Desktop.
ftp command line
import ftplib
def command():
cmd = raw_input(login +"@" + host +">")
#upload
if cmd=="upload":
filename = raw_input("Insert file name:")
#Upload a binary file from your disk
ftp.storbinary('STOR '+filename, open(filename,'rb'))
print "file upload success!"
command()
#download
if cmd=="download":
filenameHost = raw_input("Insert file name (on server):")
filename = raw_input("Insert file name (in your disk):")
ftp.retrbinary('RETR '+filenameHost, open(filename,'wb').write)
print "file download success!"
command()
#cambia directory
if cmd=="cd":
newDir = raw_input("new dir:")
ftp.cwd(newDir)
#visualizzo tutti i file della directory
print ftp.retrlines("LIST")
command()
#help
if cmd=="help":
print "-------------------------------------------------"
print ".:[ ByteZoneFtp Help ]:."
print ""
print "Aviable commands:"
print "- upload (upload files from your disk to server)"
print "- download (download files from server)"
print "- cd (change directory)"
print "- quit"
print "-------------------------------------------------"
command()
#quit
if cmd=="quit":
print "quit from " + host
print "------------------------------"
print "ByteZoneFtp v0.1 Beta"
print "by Nemolog"
print ""
print "follow me http://plumfake.net"
print "------------------------------"
ftp.quit()
exit()
#ripropongo il comando
else:command()
print "------------------------------"
print "Wellcome ByteZoneFtp v0.1 Beta"
print "by Nemolog"
print ""
print "follow me http://plumfake.net"
print "------------------------------"
host = raw_input("Insert Host:")
login = raw_input("Insert Login:")
psw = raw_input("Insert Password:")
directory = raw_input("Insert direcory (default '/'):")
if directory == "": directory = "/"
print "try connect to " + login +"@" + host +"..."
try: ftp = ftplib.FTP(host)
except ftp.all_errors, error:
print "Cannot connect:", error
else:
#provo a collegarmi...
try: ftp.login(login, psw)
except ftp.all_errors, error:
print "Cannot login:", error
else:
#benvenuto...
print ftp.getwelcome()
ftp.cwd(directory)
#visualizzo tutti i file della directory
print ftp.retrlines("LIST")
command()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment