473,385 Members | 1,602 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,385 software developers and data experts.

ftplib help - delete from server after download results in 0-byte file

Got a strange scenario going on here in that I could have sworn this worked
yesterday. I am issuing binary retrieval calls to an FTP server, writing to a
file, close the file, then removing the file from the remote site. When I do
this, I end up with 0 byte files. I was hoping to avoid parsing a list of
remote and local files and matching them up that way because it would be easier
to remove on successful retrieve. I'm including some sample code and really
hoping someone can point out where I'm messing up.

import os, ftplib
DPI = "C:/DestinationFolder/"
#Actually named different in code, but shorter for reading here.
#Note - objFTP is already opened - this is not the issue.


#I'm open to better ways to do this. Can't use nlst if empty.
TestDir = objFTP.dir()
if TestDir <> None:
FTPRemoteList = objFTP.nlst()

#If the remote file is type SEM or PGP, do this.
for filename in [filename for filename in FTPRemoteList if \
(os.path.splitext(filename)[1] in [".sem",".SEM",".PGP",".pgp"])]:
DestinationFile = open(os.path.join(DPI, filename), "wb")
print DestinationFile
objFTP.retrbinary("RETR " + filename, DestinationFile.write)
SQLLogging.LogFTP(filename, CompanyInput, 1, 'ToDrive')

#This is the culprit. When this is active, it writes a 0 byte file locally
# and deletes the file on the server.
SQLLogging.LogFTP(filename, CompanyInput, 0, 'ToUs')
print Exception
#This is my workaround in the meantime. If I've downloaded the files, get
#another remote listing and delete and files from remote that are downloaded
#locally and larger than 1Kbish for PGP files. SEM files are 0 bytes.

TestDir = objFTP.dir()
if TestDir <> None:
FTPRemoteList = objFTP.nlist()
for filename in FTPRemoteList:
if os.path.isfile(os.path.join(DownloadedPathInput, filename)) and \
os.path.splitext(filename)[1] in [".pgp",".PGP"] and \
os.stat(os.path.join(DownloadedPathInput, filename))[6] > 1000:
if os.path.isfile(os.path.join(DownloadedPathInput, filename)) and \
os.path.splitext(filename)[1] in [".SEM",".sem"]:

Jul 18 '05 #1
0 1796

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

Similar topics

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. ...
by: John fabiani | last post by:
Hi, I have a script that is not running on a freeBSD 4.4 with Python 2.1 that uses ftplib. I'm wondering if it's possible to update only the ftplib module from 2.1 to 2.3. I only ask because I...
by: Mikael | last post by:
Hello, I am using the ftplib.FTP.nlst() method to list the files in a directory on a FTP server. But when the directoty is empty, python raises an error: ftplib.error_perm: 550 No files...
by: Beeyah | last post by:
in my inability to find a working ftp program for my mac, i decided to write one in python. i wrote a class (link at end of post) that inherited ftplib.FTP and made the process slightly less...
by: Matija Papec | last post by:
I would like to reimplement ftplib "nlst" using ftplib.dir (ftp server doesn't support nlst) so I'm trying to guess how to use ftp callbacks. Any help is appreciated. tia! ============...
by: Peter A. Schott | last post by:
Using ftplib.FTP object for a project we have here to upload/download files. I know that I can wrap everything in try/except blocks, but I'm having trouble getting the exact error messages out of...
by: eight02645999 | last post by:
hi my purpose is just to connect to an FTP server and delete all files in a directory Is there a way using ftplib module? something like ftp.delete("*") ? another way i can do is using LIST to...
by: vedran | last post by:
Hello, One simple question.Which security ftplib support,and how to I 'load' these security to ftputil. (Please don't give me security modules) e.g. ...
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 ...
by: Laszlo Nagy | last post by:
Hi All, I'm using a simple program that uploads a file on a remote ftp server. This is an example (not the whole program): def store(self,hostname,username,password,destdir,srcpath):...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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$) { } ...
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...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.