Client FTP che permette il download e l'upload di file:
Codice:
import ftplib
def menu():
print "1) Download file"
print "2) Upload file"
def data():
global server, user, passw
server = raw_input("Server: ")
user = raw_input("User: ")
passw = raw_input("Password: ")
def download():
connection = FTP(server, user, passw)
connection.retrlines("LIST")
f = raw_input("File to download: ")
f2 = f
file_open = open(f, "wb")
connection.retrbinary("RETR " + f2, file_open.wirte)
file_open.close()
connection.quit()
print "Download completed."
def upload():
connection = FTP(server, user, passw)
f = raw_input("File to hostie: ")
f2 = f
file_open = open(f, "rb")
connection.storbinary("STOR " + f2, file_open)
file_open.close
connection.quit()
print "Upload completed."
print " ---------- FTP Client ----------\n"
menu()
print
while True:
choice = raw_input("Choose an option: ")
if choice == "1":
data()
download()
break
elif choice == "2":
data()
upload()
break
else:
print "Invalid choice."