Guest User

Untitled

a guest
Dec 17th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | None | 0 0
  1. import ftplib, os, sys, time
  2. from ftplib import FTP
  3.  
  4. def main():
  5.     print "(1) Connect to an FTP server"
  6.     print "(2) Exit Program\n"
  7.     option = int(raw_input("=> "))
  8.  
  9.     if option == 1:
  10.         connect()
  11.     elif option == 2:
  12.         sys.exit()
  13.     else:
  14.         print "Error! Closing program"
  15.         sys.exit()
  16.        
  17. def connect():
  18.     os.system("cls" or "clear")
  19.     # hostname = raw_input("Enter the FTP hostname: ") # Remember to uncomment once working!
  20.     # username = raw_input("Enter the FTP username: ")
  21.     # password = raw_input("Enter the FTP password: ")
  22.    
  23.     hostname = "removed for obvious reasons" # This is just for testing purposes
  24.     username = "username"
  25.     password = "password"
  26.    
  27.     ftp = FTP(hostname, username, password)
  28.     os.system("cls" or "clear")
  29.     print "\nConnected to " + hostname
  30.     time.sleep(2)
  31.     command(ftp)
  32.  
  33. def command(ftp):
  34.     print "\n"
  35.     cmd = raw_input("=> ")
  36.    
  37.     if cmd == "mkd": # Make a directory
  38.         dirname = raw_input("Directory name => ")
  39.         ftp.mkd(dirname)
  40.         print dirname + " has been created"
  41.         command(ftp)
  42.        
  43.     elif cmd == "exit":
  44.         sys.exit()
  45.  
  46.     elif cmd == "commands":
  47.         print "Coming soon..."
  48.         command(ftp)
  49.  
  50.     elif cmd == "help":
  51.         print "Type 'commands' for a list of commands"
  52.         command(ftp)
  53.  
  54.     elif cmd == "cls": # Clears the terminal screen
  55.         os.system("cls")
  56.         command(ftp)
  57.  
  58.     elif cmd == "clear": # Same as above
  59.         os.system("clear")
  60.         command(ftp)
  61.  
  62.     elif cmd == "listinfo": # Lists the file & dir names and info
  63.         ftp.retrlines('LIST')
  64.         command(ftp)
  65.  
  66.     elif cmd == "listnames": # Lists just the names
  67.         ftp.retrlines('NLST')
  68.         command(ftp)
  69.        
  70.     elif cmd == "rename": # Rename a file/dir
  71.         currentname = raw_input("Current file/folder name => ")
  72.         renameto = raw_input("Rename to => ")
  73.         ftp.rename(currentname, renameto)
  74.         print currentname + " has been renamed to " + renameto
  75.         command(ftp)
  76.  
  77.     elif cmd == "delete": # Delete a file/dir
  78.         filetodelete = raw_input("File to delete => ")
  79.         ftp.delete(filetodelete)
  80.         print filetodelete + " has been deleted"
  81.         command(ftp)
  82.  
  83.     elif cmd == "cd": # Set the current directory
  84.         dirname = raw_input("Directory to move to => ")
  85.         ftp.cwd(dirname)
  86.         print "Current directory: " + dirname
  87.         command(ftp)
  88.  
  89.     elif cmd == "sendcmd": # Send a command
  90.         print "\n"
  91.         sendcmd = raw_input("Command => ")
  92.         command(ftp)
  93.  
  94.     elif cmd == "back": # Previous dir
  95.         ftp.cwd("..")
  96.         print "Current directory: " + ftp.pwd()
  97.         command(ftp)
  98.  
  99.  
  100. main()
Add Comment
Please, Sign In to add comment