Python FTP Download - Only download 16 files from FTP not all the files from the ftp?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • precyoz
    New Member
    • Dec 2013
    • 5

    Python FTP Download - Only download 16 files from FTP not all the files from the ftp?

    Hello everyone. I'm encountering a problem with the python ftp download. Every time I run this script and connect to my ftp site it only downloads 16 files wherein the ftp site contains almost hundred files and counting because it always update and add files everyday. I'm wondering if is it because of the internet connection or maybe there's something missing in the script to enable me to download all those files that I really can't figure out. Any help/suggestions/comments will be appreciated. Thanks!

    Here is the script:(some of it are from here http://code.activestate.com/recipes/...on-ftp-client/)

    Code:
    from ftplib import FTP
    import os, sys, os.path, operator
    import wx
    
    host_name = raw_input("Enter your FTP Site: ")
    if "http://" in host_name:
       host_name = host_name.replace("http://","")
    host_name = host_name.replace("\n","")
    user = raw_input("Enter username: ")
    pwd = raw_input("Enter password: ")
    
    try: ftph = FTP(host_name)
    except:
       print "Host could not be resolved."
       raw_input()
       sys.exit()
    else: pass
    try:
       ftph.login(user,pwd)
    except Exception:
       if user == "anonymous" or user == "Anonymous" and pwd == "anonymous" or pwd == "Anonymous":
          print "The server does not accept anonymous requests."
          raw_input()
          sys.exit()
       else:
          print "Invalid login combination."
          raw_input()
          sys.exit()
    else:
       print "Successfully connected!\n"
    print ftph.getwelcome()
    flag = 1
    count = 0
    path = ftph.pwd()
    charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
    
    def handleDownload(block):
        file.write(block)
        print ".",
    
    ddir='#localdirectory'
    os.chdir(ddir)
    ftp = FTP('#yourftpsite')
    print 'Logged in!'
    
    ftp.login('', '')
    directory = '#ftpdirectory'
    
    print 'Changing to ' + directory
    ftp.cwd(directory)
    ftp.retrlines('LIST')
    print 'Downloading files...'
    
    filenames = []
    ftp.retrlines('NLST', filenames.append)
    print filenames
    
    for filename in filenames:
        local_filename = os.path.join('#localdirectory', filename)
        file = open(local_filename, 'wb')
        ftp.retrbinary('RETR '+ filename, file.write)
    
        file.close()
        
    ftp.close()
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    ah, you ripped the stuff from this site:


    What tries did you do yourself to find out if "the internet connection" is to blame,
    or maybe there's something missing in "my script"
    but it is not your script, you copied it from the above mentioned site......

    Comment

    • precyoz
      New Member
      • Dec 2013
      • 5

      #3
      That post from the link you've given was also from my post. Please check the username. So what maybe the problem of the script?Because I can't download all the files.

      Comment

      • precyoz
        New Member
        • Dec 2013
        • 5

        #4
        I've tried to run the script several times. There were times it disconnects but there were times that it is still downloading but then there were no added files downloaded in the local directory every time I'll check on it.

        Comment

        Working...