Hi Arne,

On 2006-04-08 12:44, Arne wrote:
> I am looking for a way to put ftp returns in a variable.
>
> My OS is XP and I want to get the owner of a file. So I have to
>
> connect to ftp. But I am stacked with how I can receive this
> information and put it in a variable.

you can use a library to handle that. One of them is ftputil
( http://ftputil.sschwarzer.net/ ), which I know because I'm its
author. ;-) Surely, there are alternatives. You can search the
Python package index at http://www.python.org/pypi .

With ftputil, you would do

import ftputil
host = ftputil.FTPHost(hostname, user, password)
# st_uid is used by Python's os.(l)stat, but it's a string here,
# not an integer
user = host.stat(file_or_dir).st_uid
...
host.close()

This works only if the output of the FTP LIST command contains
the user information (which is often the case).

ftputil is pure Python and should work on OS X without problems.

If you think that installing/using an additional library is
overkill, you can extract the necessary parser code from the file
ftp_stat.py or write your own parser.

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to