473,467 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create 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 3465
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("server")
print ftp.login("anonymous", "me@work.com")

ftp.cwd("pub/Python_Applications")


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
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. ...
2
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...
6
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...
1
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 ...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.