Created
March 1, 2009 21:22
-
-
Save Nemolog/72475 to your computer and use it in GitHub Desktop.
ftp command line
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 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