473,465 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

FTP (ftplib) output capture

Hi

Has anyone caputerd the output from the std ftp lib? It seems a bit
annoying that everything is printed to stdout. It means incorporating
this into any real program is a problem. It would have been much better
if they used the std logging module and hooked up a console logger for
the feault ftp application. Alas it isnt that way.

Capturing stdout like this??? :

import sys

sys.stdout = open('bb', 'w)

But I want to re-route it to the logging module not a file , so do I
need to write a steam object?

Thanks,

Jul 31 '06 #1
2 2284
ChaosKCW wrote:
Hi

Has anyone caputerd the output from the std ftp lib? It seems a bit
annoying that everything is printed to stdout. It means incorporating
this into any real program is a problem. It would have been much better
if they used the std logging module and hooked up a console logger for
the feault ftp application. Alas it isnt that way.

Capturing stdout like this??? :

import sys

sys.stdout = open('bb', 'w)

But I want to re-route it to the logging module not a file , so do I
need to write a steam object?

Thanks,
ftplib pre-dates the standard logging system by a bit.

I think ftplib only prints stuff if you set its (the FTP class
instances') debug level to greater than 0.

If you really want to replace sys.stdout with something that passes the
data to a logger, then something like the following (untested) class
should do it:

class FileLog:
def __init__(self, log):
self.log = log
def write(self, data):
self.log.debug(data)

The best solution might be to subclass or rewrite FTP to really do what
you want. I believe one of the goals of Python-3000 is better
integration of the standard library with the new-ish standard logging
system, so if you do a good job send it in. ;-)

Peace,
~Simon

Jul 31 '06 #2
Hi

Thanks for the reply.

I will send it in when I am done :-)
Simon Forman wrote:
ChaosKCW wrote:
Hi

Has anyone caputerd the output from the std ftp lib? It seems a bit
annoying that everything is printed to stdout. It means incorporating
this into any real program is a problem. It would have been much better
if they used the std logging module and hooked up a console logger for
the feault ftp application. Alas it isnt that way.

Capturing stdout like this??? :

import sys

sys.stdout = open('bb', 'w)

But I want to re-route it to the logging module not a file , so do I
need to write a steam object?

Thanks,

ftplib pre-dates the standard logging system by a bit.

I think ftplib only prints stuff if you set its (the FTP class
instances') debug level to greater than 0.

If you really want to replace sys.stdout with something that passes the
data to a logger, then something like the following (untested) class
should do it:

class FileLog:
def __init__(self, log):
self.log = log
def write(self, data):
self.log.debug(data)

The best solution might be to subclass or rewrite FTP to really do what
you want. I believe one of the goals of Python-3000 is better
integration of the standard library with the new-ish standard logging
system, so if you do a good job send it in. ;-)

Peace,
~Simon
Aug 1 '06 #3

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. ...
5
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...
0
by: Joshua Burvill | last post by:
Hello, I am trying to print something to a print server using the following function but I get errors, does anyone have any pointers? Rgds, Josh Traceback (most recent call last): File...
2
by: siggy2 | last post by:
Hi, I'm using Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 I've noticed a strange (= not deterministic) behaviour of ftplib.py: sometimes (not always) it fails (after a variable number of...
1
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...
5
by: Richard Lewis | last post by:
Hi there, I'm having a problem with unicode files and ftplib (using Python 2.3.5). I've got this code: xml_source = codecs.open("foo.xml", 'w+b', "utf8") #xml_source = file("foo.xml",...
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: 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...
0
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,...
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...
0
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,...
0
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...
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
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...
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.