473,756 Members | 5,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

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

objFTP.cwd("/ksdata_in")

#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.splite xt(filename)[1] in [".sem",".SEM"," .PGP",".pgp"])]:
try:
DestinationFile = open(os.path.jo in(DPI, filename), "wb")
print DestinationFile
objFTP.retrbina ry("RETR " + filename, DestinationFile .write)
SQLLogging.LogF TP(filename, CompanyInput, 1, 'ToDrive')
DestinationFile .close()

#This is the culprit. When this is active, it writes a 0 byte file locally
# and deletes the file on the server.
#objFTP.delete( filename)
except:
SQLLogging.LogF TP(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(Do wnloadedPathInp ut, filename)) and \
os.path.splitex t(filename)[1] in [".pgp",".PG P"] and \
os.stat(os.path .join(Downloade dPathInput, filename))[6] > 1000:
objFTP.delete(f ilename)
if os.path.isfile( os.path.join(Do wnloadedPathInp ut, filename)) and \
os.path.splitex t(filename)[1] in [".SEM",".se m"]:
objFTP.delete(f ilename)

Jul 18 '05 #1
0 1835

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

Similar topics

3
19840
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')
1
1774
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 have no idea how to upgrade anything for freeBSD 4.4. I know there is are doc's available but I sure don't want to screw anything up on the freeBSD 4.4 server because I didn't understand what I was doing. Thanks John
0
1664
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 found. I find this behaviour very strange. Why not simply return an empty list?
0
1082
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 involved, but it brought up a few questions: using the sendcmd() method to do a simple "LIST" command returns an error explaining that a data connection could not be opened, just as if you connected to a ftp server using telnet. so, you use the...
2
2951
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! ============ #!/usr/bin/python # nlst vs list
1
1793
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 the Exceptions. I'd like to either send an e-mail or log the failure to a database. It would also be nice to see what the message is and perhaps add some additional logic for delay/retry or something similar. Has anyone done any of the...
1
1367
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 list out all the files in that directory, grab the filename, append to an array, then do a for loop to delete one by one. using the ftplib retrlines('LIST') , it shows me all the lines with -rw-r--r-- 1 user grp 6302 Apr 7 15:30 some...
0
980
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. ftp=FTPHost('myhost','myusername','mypassword',session_factory=ftplib.FTP)
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?
1
4130
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): self.ftp = ftplib.FTP(hostname) self.ftp.login(username,password) self.ftp.set_pasv(False)
0
9454
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9271
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9868
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...
0
9707
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...
0
8709
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6533
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
5139
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3804
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
3352
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.