This is the place for queries that don't fit in any of the other categories.
Hello everyone. I'm encountering a problem with my 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 really can't figure out what's missing in my script to download all those files. Any help/suggestions/comments will be appreciated. Thanks!
Here is the script:
- Code: Select all
from ftplib import FTP
import os, sys, os.path, operator
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)
print "Host could not be resolved."
if user == "anonymous" or user == "Anonymous" and pwd == "anonymous" or pwd == "Anonymous":
print "The server does not accept anonymous requests."
print "Invalid login combination."
print "Successfully connected!\n"
flag = 1
count = 0
path = ftph.pwd()
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
ftp = FTP('#yourftpsite')
print 'Logged in!'
directory = '#ftpdirectory'
print 'Changing to ' + directory
print 'Downloading files...'
filenames = 
for filename in filenames:
local_filename = os.path.join('#localdirectory', filename)
file = open(local_filename, 'wb')
ftp.retrbinary('RETR '+ filename, file.write)
- Posts: 18
- Joined: Wed Jul 03, 2013 6:23 am
Your code is difficult to read and not well structured, so it's difficult to know where to start here. If you check the value of filenames before the loop, is it just 16 file names long?
Join the #python-forum IRC channel on irc.freenode.net!
Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
- Posts: 1390
- Joined: Tue Feb 12, 2013 2:18 am
- Location: Mountain View, CA
I do not really understand your method. Why not use FTP.nlst to retrieve a list of filenames on the ftp, then iterate through them to download?
Python: 2.7 via Anaconda
OS: Windows 7
- Posts: 123
- Joined: Mon Mar 11, 2013 7:41 pm
Return to General Coding Help
Who is online
Users browsing this forum: Bing [Bot], Crimson King, Google [Bot], Majestic-12 [Bot], snippsat and 4 guests