473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with FTPLib and incomplete files on some downloads

I download a lot of 4-6 KB files and regularly run into issues with files that
don't get downloaded all the way or otherwise get corrupt.

I do something like:

RemoteList = nlstdir()
for filename in RemoteList:
LocalFile = open(filename, "wb")
LocalFile.write ( "get file code here" )
LocalFile.close ()
#ftplib call to delete the remote file

I've tried to insert a pause into the code between the close and the remote
delete, but that doesn't seem to help. For some reason it doesn't seem like the
buffer is completely written or read before the remote delete is called. That
leads to a file that's not 100% complete and thus can't be decrypted.

Any ideas on what to look for? I don't have my exact code handy at the moment
or I'd post some actual snippets. It's also not consistent or it would be a
whole lot easier to troubleshoot. :-)

Running Python 2.4.2 on Win32.

Thanks.

-Pete Schott
Jan 17 '06 #1
1 3550
Peter A.Schott wrote:
I download a lot of 4-6 KB files and regularly run into issues with files that
don't get downloaded all the way or otherwise get corrupt.

I do something like:

RemoteList = nlstdir()
for filename in RemoteList:
LocalFile = open(filename, "wb")
LocalFile.write ( "get file code here" )
LocalFile.close ()
#ftplib call to delete the remote file

I've tried to insert a pause into the code between the close and the remote
delete, but that doesn't seem to help. For some reason it doesn't seem like the
buffer is completely written or read before the remote delete is called. That
leads to a file that's not 100% complete and thus can't be decrypted.

Any ideas on what to look for? I don't have my exact code handy at the moment
or I'd post some actual snippets. It's also not consistent or it would be a
whole lot easier to troubleshoot. :-)

Running Python 2.4.2 on Win32.

Thanks.

-Pete Schott

Pete,
Not sure but here is an example that seems to always work for me:
(tested this morning before pasting here on ~20 files around 7 - 300 k)

import ftplib
import os

os.chdir("D:/TEMP/dump")

ftp = ftplib.FTP("ser ver")
print ftp.login("anon ymous", "me@work.co m")

ftp.cwd("pub/Python_Applicat ions")


for rFile in ftp.nlst():
print "Getting : ", rFile
rSize = ftp.size(rFile)
lFile = open(rFile, "wb")
ftp.retrbinary( "RETR %s" %rFile, lFile.write)
lSize = lFile.tell()
lFile.close()
if rSize==lSize:
print "Transfer complete"
else:
print "BAD Transfer", rSize, lSize
ftp.close()

HTH
Martin


Jan 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
19841
by: python | last post by:
Hi: I want to write a procedure to automatically upload some files for me, but I'm getting stuck. Before I write my own gruesome put() function, I wanted to check if there is an easier way. Here's what I can do so far: >>>import ftplib >>>conn = ftplib.FTP('ftp.example.com') >>>conn.login(user='userid', passwd='passwd')
2
9583
by: Harlin Seritt | last post by:
Using ftplib from Python I am trying to get all files in a particular directory using ftplib and then send those same files to another ftp server. I have tried using commands like 'get *' and 'mget *' with no success. I am using the following: srcFtp = FTP(srcHost) srcFtp.login(srcUser, srcPass) srcDir = srcFtp.nlst('.')
6
5782
by: half.italian | last post by:
Hi all, I'm using ftplib to transfer large files to remote sites. The process seems to work perfectly with small files, but when the file gets to large ~20GB I begin getting errors that sometimes seem to be non- fatal, and other times the transfer does not complete. I've debugged the hell out of the code, and can't figure out what is going on..is it the remote site? Packet loss? Traceback (most recent call last):
1
6100
by: loial | last post by:
Trying to use ftplib.FTP.nlst() method to list the files in a directory on a FTP server. It works fine except when there are no files in the directory. Then it gives the error ftplib.error_perm: 550 No files found. How can I handle this cleanly?
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.