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

FTP transfert

Hi,

given this code:
from ftplib import FTP

connection = FTP('ftp.python.org')
connection.login()
connection.dir()
connection.close()

The script write on the standart output a list of files and directories
present on the server. Good. But how can I have this output in a string
that I can work with ? sys.stdout is an open file object, is'nt it ?
So if I do :

string_out = sys.stdout.readlines()

the script of course freeze. (what is for me logic)

How can I solve the problem ?

Why connection.sendcmd('ls') does not work ? the same for
connection.sendcmd('LIST') ? 'ls' is a valid ftp command. In the RFC of
FTP the commands are differents as the one I use every day : no get,
mget, put, mput, ... but LIST, RETR, ... what is the difference ?

Thanks for your help

Antoine

Jul 18 '05 #1
4 1787
Antoine Logean <al@biolinux.ch> writes:
connection = FTP('ftp.python.org')
connection.login()
sys.stdout = open(outfilename, "w")
connection.dir()
connection.close()

Jul 18 '05 #2
Antoine Logean <al@biolinux.ch> writes:
connection.dir()


Check the docs for this method; it can take an argument, a callback
function. You can probably have this function build the representation
you want.
Jul 18 '05 #3
Antoine Logean wrote:
from ftplib import FTP

connection = FTP('ftp.python.org')
connection.login()
connection.dir()
connection.close()

The script write on the standart output a list of files and directories
present on the server. Good. But how can I have this output in a string
that I can work with ? sys.stdout is an open file object, is'nt it ?


Seems like dir() accepts a callback that takes one argument, so you need not
mess with stdout. E. g.:

from ftplib import FTP

connection = FTP('ftp.python.org')
connection.login()
lines = []
connection.dir(lines.append)
connection.close()

print "\n".join(lines)

Peter

Jul 18 '05 #4
Antoine Logean <al@biolinux.ch> writes:
Hi, Why connection.sendcmd('ls') does not work ? the same for
connection.sendcmd('LIST') ? 'ls' is a valid ftp command. In the RFC of
FTP the commands are differents as the one I use every day : no get,
mget, put, mput, ... but LIST, RETR, ... what is the difference ?


The RFC commands constitute the protocol between FTP servers/clients and are
specified (reasonably) exactly to get good interworking between different
implementations. The dir, ls, get etc commands constitute the user interface
and are modelled on what a user on that system might expect to know. The
Python library, unusually for Python, does not do much in the way of hiding
the protocol level commands. Perhaps there are some 3rd party addons to add a
more user friendly level, the vaults of Parnassus
(http://www.vex.net/parnassus/) seems to have some promising libraries.

Eddie
Jul 18 '05 #5

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

Similar topics

1
by: David Chaumeil | last post by:
I have an ODBC link to DB2 Database. I can see the values of the DB2's tables in Access but not in SQL Server DTS. IN DTS, I connect the Source but when i want to see the values in the Data...
3
by: Eric Caron | last post by:
Hi Here's my XML file : <?xml version="1.0" encoding="utf-8"?> <ApplicationSettings> <Section Name="Transfert"> <Key Name="m_blnTransfRoleBD" Value="True" /> <Key...
3
by: etienno | last post by:
Hi, what would be the best way to transfert high volume data (100 tables, 500Meg each) between DB2/AS400 to Sybase? Thanks Etienne. Montreal
0
by: lukas | last post by:
i want to fill a daset with Excel data. For this i do OleDbDataAdapter oCmd=new OleDbDataAdapter("SELECT * FROM ",strCn); DataSet oDS=new DataSet(); try { oCmd.Fil(oDS,"ExcelInfo");...
3
by: Alexandre Jaquet | last post by:
Hi, I currently design an application for sending files between two users and having questions about the transfert of files. What's the best I can do to ensure files are send, I will need a...
0
by: Simon | last post by:
Hello, I have an ASP.NET site using C#. I work with frames : One top, left and center (bottom right). When, in the center, I push on a datagrid button, the page transfert me to another page in...
4
by: Mathieu | last post by:
How can I transfert a file on the mainframe to my PC with VB.NET ???
1
by: a | last post by:
Hi, anyone has a piece of code to use Backgroud Intelligent Transfert Service. I'want to write mass files synchronisation over the net. Sorry for my English ... and thank you Geo
1
by: makram2006 | last post by:
I want to transfert a page when my web user click on an ASP button, but I have this exception "Thread was being aborted". I think that comes from Server.Transfert(url) method. Please help me as soon...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
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
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...
0
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...

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.