473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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

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('#yourftpsite')
  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()
Jan 5 '14 #1
3 3423
Luuk
1,047 Expert 1GB
ah, you ripped the stuff from this site:
http://www.dreamincode.net/forums/to...rectories-gui/

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......
Jan 5 '14 #2
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.
Jan 6 '14 #3
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.
Jan 6 '14 #4

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

Similar topics

5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
5
by: Thomas Andersson | last post by:
Hi, I am trying to find a working solution for download of large files (400-800 MB)... But this seems almost impossible to find a working example. I have tried Response.Transmitfile, this...
1
by: Marc Pelletier | last post by:
Hello all, I am a desktop programmer getting my feet wet on the web. I am trying to build a .net website that will keep a set of local files synchronized with a master set on the web. Using a...
0
by: Chuck Anderson | last post by:
I am writing a Php script to run on my home PC (Windows) that downloads an Apache access log file and inserts new entries into a database.. The only way I can access these log files is through a...
1
by: Al | last post by:
Hi! I try to use custom download page (download.aspx) wich writes file (about 700Mb) to response. But I can download only one file from one IP at the same time. I think that this is IIS or...
1
by: moishyyehuda | last post by:
I need to download files off a password protected website. So if I try to download files off the site with python I will be blocked. Is there anyway to send cookies with python. So I will be...
1
by: vc4free | last post by:
Hello Everyone, I am trying to write a simple program to download files from tftp server, but I am have a very difficult time doing so because I am very very new to python. I have...
5
by: T_T | last post by:
Hi, I'm just starting to learn some Python basics and are not familiar with file handling. Looking for a python scrip that zips files. So aaa.xx bbb.yy ccc.xx should be zipped to aaa.zip...
6
by: empiresolutions | last post by:
Using the following code, files greater than 10Megs do not download. Less than 10 is working. Can anyone explain why? Files that will be downloaded are 5G plus in size. function download() {...
10
by: =?Utf-8?B?SnVhbg==?= | last post by:
Hi! I want to use ASP to download big files using ADODB.STREAM. It works very fine with files smaller than 80 MB. On the Webserver I can see that memory allocation and the process w3wp is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.