Advertisement
berzerker101a

FTP Client v1.7

Jan 14th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.36 KB | None | 0 0
  1. #FTP Client tool v1.7 by Berzerker
  2.  
  3. import os
  4. import sys
  5. import ftplib
  6. import urllib
  7. from ftplib import FTP
  8.  
  9. os.system("clear")
  10. print("=") * 50
  11. print("FTP Client")
  12. print("v1.7")
  13. print("=") * 50
  14. ftp=raw_input("Enter FTP server: ")
  15. username=raw_input("Enter username: ")
  16. password=raw_input("Enter password: ")
  17. server=FTP(ftp)
  18. server.login(username,password)
  19. os.system("clear")
  20. print("=") * 50
  21. print("FTP Client")
  22. print("v1.7")
  23. print("=") * 50
  24. print("You are connected to FTP server...")
  25. print("You may use the terminal now...")
  26. print("You can type help to pull up the help menu...")
  27. print("You can type about to pull up the credits...")
  28. while True:
  29.      try:
  30.           command=raw_input("==>")
  31.           if command=="about":
  32.                print("Head programmer - Berzerker")
  33.                print("Code hosting - http://pastebin.com")
  34.                print("Special thanks - All of Psyko Security")
  35.           elif command=="help":
  36.                print("The following are commands that can be used...")
  37.                print("Type help(COMMAND) for more details...")
  38.                print("Type about for the credits...")
  39.                print("clear_scr - Clear the screen")
  40.                print("cwd - Change directory")
  41.                print("pwd - Display current directory")
  42.                print("dir - List directories")
  43.                print("nlst - List file names")
  44.                print("size - Returns the size of a file")
  45.                print("rename - Rename a file")
  46.                print("delete - Delete a file")
  47.                print("mkd - Make a directory")
  48.                print("rmd - Remove a directory")
  49.                print("retr - Retrieve a file")
  50.                print("stor - Store a file")
  51.                print("close - Closes the connection")
  52.           elif command=="help(clear)":
  53.                print("Clears the screen...")
  54.           elif command=="help(cwd)":
  55.                print("Changes directory")
  56.                print("Format: cwd DIRECTORYNAME")
  57.           elif command=="help(pwd)":
  58.                print("Displays the current directory")
  59.           elif command=="help(dir)":
  60.                print("List directories")
  61.           elif command=="help(nlst)":
  62.                print("Lists file names")
  63.           elif command=="help(size)":
  64.                print("Returns the size of a file")
  65.                print("Format: size FILE")
  66.           elif command=="help(rename)":
  67.                print("Renames a file")
  68.                print("Format: rename FROM TO")
  69.           elif command=="help(delete)":
  70.                print("Deletes a file")
  71.                print("Format: delete FILE")
  72.           elif command=="help(mkd)":
  73.                print("Make a directory")
  74.                print("Format:mkd PATHNAME")
  75.           elif command=="help(rmd)":
  76.                print("Remove a directory")
  77.                print("Format: rmd PATHNAME")
  78.           elif command=="help(retr)":
  79.                print("Retrieve a file")
  80.                print("Format: retr FILENAME")
  81.           elif command=="help(stor)":
  82.                print("Store a file")
  83.                print("Format: stor FILENAME")
  84.           elif command=="help(close)":
  85.                print("Closes the connection")
  86.           elif command=="clear":
  87.                os.system("clear")
  88.           elif "cwd" in command:
  89.                part1, part2=command.split(" ")
  90.                server.cwd(part2)
  91.                path=server.pwd()
  92.           elif command=="pwd":
  93.                response=server.pwd()
  94.                print(response)
  95.           elif command=="dir":
  96.                server.dir()
  97.           elif command=="nlst":
  98.                response=server.nlst()
  99.                print(response)
  100.           elif "size" in command:
  101.                part1, part2=command.split(" ")
  102.                response=server.size(part2)
  103.                print(response)
  104.           elif "rename" in command:
  105.                part1, part2, part3=command.split(" ")
  106.                server.rename(part2, part3)
  107.                print("File renamed!")
  108.           elif "delete" in command:
  109.                part1, part2=command.split(" ")
  110.                server.delete(part2)
  111.                print("File deleted!")
  112.           elif "mkd" in command:
  113.                part1, part2=command.split(" ")
  114.                server.mkd(part2)
  115.                print("Directory created!")
  116.           elif "rmd" in command:
  117.                part1, part2=command.split(" ")
  118.                server.rmd(part2)
  119.                print("Directory removed!")
  120.           elif "retr" in command:
  121.                part1, part2=command.split(" ")
  122.                def getbinary(ftp, filename, outfile=None):
  123.                     if outfile is None:
  124.                          outfile = sys.stdout
  125.                     server.retrbinary("RETR " + filename, outfile.write)
  126.                     print()
  127.                getbinary(server, part2)
  128.           elif "stor" in command:
  129.                part1, part2=command.split(" ")
  130.                def upload(ftp, file):
  131.                     ext = os.path.splitext(file)[1]
  132.                     if ext in (".txt", ".htm", ".html"):
  133.                          server.storlines("STOR " + file, open(file))
  134.                     else:
  135.                          server.storbinary("STOR " + file, open(file, "rb"), 1024)
  136.                upload(server, part2)
  137.           elif command=="close":
  138.                server.close()
  139.                print("Connection closed")
  140.                os.system("exit")
  141.      except ftplib.all_errors:
  142.           print("An error occurred...")
  143. print("Goodbye...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement