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/)
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()
Comment