By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,360 Members | 1,382 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,360 IT Pros & Developers. It's quick & easy.

FTP Client

P: 5
I have a code here and I just want to ask if what are the missing codes or what should I add so that every time I'm going to run this code a GUI will already appear and not the IDE/console anymore.


Expand|Select|Wrap|Line Numbers
  1. from ftplib import FTP
  2. import os, sys, os.path, operator
  3. import wx
  4.  
  5. host_name = raw_input("Enter your FTP Site: ")
  6. if "http://" in host_name:
  7.     host_name = host_name.replace("http://","")
  8. host_name = host_name.replace("\n","")
  9. user = raw_input("Enter username: ")
  10. pwd = raw_input("Enter password: ")
  11.  
  12. try: ftph = FTP(host_name)
  13. except:
  14.     print "Host could not be resolved."
  15.     raw_input()
  16.     sys.exit()
  17. else: pass
  18. try:
  19.     ftph.login(user,pwd)
  20. except Exception:
  21.     if user == "anonymous" or user == "Anonymous" and pwd == "anonymous" or pwd == "Anonymous":
  22.         print "The server does not accept anonymous requests."
  23.         raw_input()
  24.         sys.exit()
  25.     else:
  26.         print "Invalid login combination."
  27.         raw_input()
  28.         sys.exit()
  29. else:
  30.     print "Successfully connected!\n"
  31. print ftph.getwelcome()
  32. flag = 1
  33. count = 0
  34. path = ftph.pwd()
  35. charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
  36.  
  37. def handleDownload(block):
  38.     file.write(block)
  39.     print ".",
  40.  
  41. ddir='#localdirectory'
  42. os.chdir(ddir)
  43. ftp = FTP('#ftpsite')
  44. print 'Logged in!'
  45.  
  46. ftp.login('', '')
  47. directory = '#ftpdirectory'
  48.  
  49. print 'Changing to ' + directory
  50. ftp.cwd(directory)
  51. ftp.retrlines('LIST')
  52. print 'Downloading files...'
  53.  
  54. filenames = []
  55. ftp.retrlines('NLST', filenames.append)
  56. print filenames
  57.  
  58. for filename in filenames:
  59.     local_filename = os.path.join('#localdirectory', filename)
  60.     file = open(local_filename, 'wb')
  61.     ftp.retrbinary('RETR '+ filename, file.write)
  62.  
  63.     file.close()
  64.  
  65. ftp.close()
  66.  
Jan 2 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.