473,834 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to trap errors in ftplib?

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 above? Willing to share some samples?

Here's a little of my code - maybe you can see what I'm doing/not doing.

def myuploadbinaryf unction(args here):
objFTP = ftplib.FTP(Host Name, UserName, Password)
objFTP.cwd(Remo tePath)

objFTP.storbina ry("STOR " + RemoteFile, file(os.path.jo in(LocalPath,
LocalFile), "rb"))
SQLLogging.LogF TP(LocalFile, Company, 1)
except Exception, errObj:
SQLLogging.LogF TP(LocalFile, Company, 0)
reportError("Fa iled to upload " + LocalFile, str(errObj))
print Exception
print errObj

In the above, reportError will send an e-mail to alert. I realize that the
errObj in this case may not have the ability to convert to string, but am not
sure how to get the output otherwise. Not sure how to handle a retry of a
failure, either.

Thank you for your help!

-Peter Schott
Jul 18 '05 #1
1 1800
Peter A.Schott wrote:
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.

Consider using the traceback a la:

[... whatever ...]
import sys, traceback
t, v, tb = sys.exc_info()
# or use StringIO to "print" the traceback to and then log *that*
traceback.print _tb(tb)

// m
Jul 18 '05 #2

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. Here's what I can do so far: >>>import ftplib >>>conn = ftplib.FTP('ftp.example.com') >>>conn.login(user='userid', passwd='passwd')
by: HankC | last post by:
Greetings: I'm been programming Delphi for a while and am trying to get into the Python mindset. In Delphi, you can have a component class that has properties, methods, and events. Properties and methods translate pretty easily to Python but I'm not sure about the best way to handle events. For example, from fxn retrbinary in ftplib there is: while 1: data = conn.recv(blocksize)
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of files via FTP. I'm using ftplib to do it, and for each file I'm using transfercmd("STOR " + myfile) to get the socket, then uploading 4096 bytes at a time and providing status updates via a GUI interface. Finally, I close the socket, set it to...
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
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
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('.')
by: Merrigan | last post by:
Hi All, I have written a little script to upload some files to an ftp folder. The problem is as follows : I wrote the script on my windows laptop, and I want to run it from mylinux server. Everything worked fine so I uploaded it to my linux machine. Every time I tun the script I get the following error: ***************************************************************************************************************************
by: Jon Bowlas | last post by:
Hi All, I've written a little method to connect to an ftpserver which works well, however when I send a file using this ftp connection oddly I _sometimes_ get returned an EOFError from ftplib.getline even though my file is actually transferred. Here's my script: def uploadViaFtp(self, file, filename):
by: bhass | last post by:
From my other post I am making a simple program that creates an RSS feed with Python. Now when I run my program so far, I get errors. It says "something is not defined". The word something is replaced by the name of the function I'm trying to use. my article function when ran, comes up with "article is not defined" etc. Here's my code: What is wrong with it? #!/usr/bin/env python import ftplib import getpass def mainfeed(): ...
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...
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,...
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,...
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...
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...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.