Guest User

Untitled

a guest
Aug 8th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. Python 2.7 Tkinter and ftplib
  2. # Import the FTP object from ftplib
  3. from ftplib import FTP
  4. from Tkinter import *
  5.  
  6. app = Tk()
  7. app.title("FTP")
  8. app.geometry("300x500")
  9.  
  10. def handleDownload(block):
  11. file.write(block)
  12. print ".",
  13.  
  14. def login():
  15. ftp.login(username.get(),password.get())
  16.  
  17. # This is where I am held up I tried ftp.retrlines('LIST') but it would
  18. # not be inserted into to the list box instead it inserted "Tranfer Complete" at the end!
  19. # Any suggetion?
  20. h = ?
  21. stuff = Listbox(app)
  22. stuff.insert(END, h)
  23. stuff.pack()
  24.  
  25. filename = "Steam Engine Poster.pdf"
  26.  
  27. Label(app, text ='Opening local file ' + filename).pack()
  28. file = open(filename, 'wb')
  29.  
  30. Label(app, text = "Downloading Steam Engine Poster.pdf").pack()
  31.  
  32. ftp.retrbinary('RETR ' + filename, handleDownload)
  33.  
  34. Label(app, text = "Closing FTP connection!").pack()
  35.  
  36. ftp.close()
  37.  
  38.  
  39.  
  40. ftp = FTP('sciphigames.com')
  41. Label(app, text = "Login").pack()
  42.  
  43. username = StringVar(None)
  44. username = Entry(app, text = "Username: ")
  45. username.pack()
  46.  
  47. password = StringVar(None)
  48. password = Entry(app, text = "Password: ")
  49. password.pack()
  50.  
  51. button = Button(app, text = "Login!", command = login)
  52. button.pack()
  53.  
  54. app.mainloop()
  55.  
  56. lines = []
  57. def append_line(line):
  58. lines.append(line)
  59. ftp.retrlines('LIST', append_line)
Add Comment
Please, Sign In to add comment