Guest User

Untitled

a guest
Oct 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import os
  2. from tkinter import filedialog, Tk, Label, Button
  3. import paramiko
  4. import urllib.parse
  5. import os
  6. from pathlib import Path
  7.  
  8. class MyGUI:
  9. def __init__(self, master):
  10. self.master = master
  11. master.title("Server Uploader")
  12. master.resizable(height=False, width=False)
  13. master.configure(bg="white")
  14.  
  15. self.label = Label(master, text="There was a problem connecting to the server. Please try again later or contact me.", fg="black", bg="white")
  16. self.label.config(font=("Courier", 12))
  17. self.label.pack()
  18.  
  19. class SuccessfulUpload:
  20. def __init__(self, master):
  21. self.master = master
  22. master.title("Successful Upload")
  23. master.resizable(height=False,width=False)
  24.  
  25. self.label = Label(master, text="Upload successful. You can now close this window.")
  26. self.label.config(font=("Courier, 12"))
  27. self.label.pack()
  28.  
  29. #Connect to server using SFTP
  30. ssh_client = paramiko.SSHClient()
  31. ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  32. try:
  33. ssh_client.connect(hostname='hostname',port=portno,username='username',password='password')
  34. except paramiko.ssh_exception.AuthenticationException as e:
  35. root = Tk()
  36. my_gui = MyGUI(root)
  37. root.mainloop()
  38. raise SystemExit
  39.  
  40. #Ask for user to choose files to upload
  41. root = Tk()
  42. root.withdraw()
  43. files = filedialog.askopenfilenames(title="Choose Files to Upload to the Server", filetypes=(("All Files","*.*"),("PDF Files","*.pdf"), ("Word Files","*.doc*")))
  44. print (root.tk.splitlist(files))
  45.  
  46. s = ssh_client.open_sftp()
  47. if files == "":
  48. raise SystemExit
  49.  
  50. #Define local and remote path for file
  51. for file in files:
  52. localpath = file
  53. parts = Path(file).parts
  54. endpath = parts[-1]
  55. print(endpath)
  56. remotepath="/Path/" + endpath
  57. print(remotepath)
  58. s.put(localpath,remotepath)
  59.  
  60. root = Tk()
  61. fin = SuccessfulUpload(root)
  62. root.mainloop()
  63.  
  64. s.close()
  65. root.destroy()
  66.  
  67. complete = input("Upload Successful. Press any key to exit.")
Add Comment
Please, Sign In to add comment