Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ftplib, os, sys, time
- from ftplib import FTP
- def main():
- print "(1) Connect to an FTP server"
- print "(2) Exit Program\n"
- option = int(raw_input("=> "))
- if option == 1:
- connect()
- elif option == 2:
- sys.exit()
- else:
- print "Error! Closing program"
- sys.exit()
- def connect():
- os.system("cls" or "clear")
- # hostname = raw_input("Enter the FTP hostname: ") # Remember to uncomment once working!
- # username = raw_input("Enter the FTP username: ")
- # password = raw_input("Enter the FTP password: ")
- hostname = "removed for obvious reasons" # This is just for testing purposes
- username = "username"
- password = "password"
- ftp = FTP(hostname, username, password)
- os.system("cls" or "clear")
- print "\nConnected to " + hostname
- time.sleep(2)
- command(ftp)
- def command(ftp):
- print "\n"
- cmd = raw_input("=> ")
- if cmd == "mkd": # Make a directory
- dirname = raw_input("Directory name => ")
- ftp.mkd(dirname)
- print dirname + " has been created"
- command(ftp)
- elif cmd == "exit":
- sys.exit()
- elif cmd == "commands":
- print "Coming soon..."
- command(ftp)
- elif cmd == "help":
- print "Type 'commands' for a list of commands"
- command(ftp)
- elif cmd == "cls": # Clears the terminal screen
- os.system("cls")
- command(ftp)
- elif cmd == "clear": # Same as above
- os.system("clear")
- command(ftp)
- elif cmd == "listinfo": # Lists the file & dir names and info
- ftp.retrlines('LIST')
- command(ftp)
- elif cmd == "listnames": # Lists just the names
- ftp.retrlines('NLST')
- command(ftp)
- elif cmd == "rename": # Rename a file/dir
- currentname = raw_input("Current file/folder name => ")
- renameto = raw_input("Rename to => ")
- ftp.rename(currentname, renameto)
- print currentname + " has been renamed to " + renameto
- command(ftp)
- elif cmd == "delete": # Delete a file/dir
- filetodelete = raw_input("File to delete => ")
- ftp.delete(filetodelete)
- print filetodelete + " has been deleted"
- command(ftp)
- elif cmd == "cd": # Set the current directory
- dirname = raw_input("Directory to move to => ")
- ftp.cwd(dirname)
- print "Current directory: " + dirname
- command(ftp)
- elif cmd == "sendcmd": # Send a command
- print "\n"
- sendcmd = raw_input("Command => ")
- command(ftp)
- elif cmd == "back": # Previous dir
- ftp.cwd("..")
- print "Current directory: " + ftp.pwd()
- command(ftp)
- main()
Add Comment
Please, Sign In to add comment