469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

ftp putting information in a variable

Hello!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.Thanks! ArneHere is a intend of doing thisfrom ftplib import FTP
ftp = FTP('ftp.cwi.nl') # connect to host, default port
ftp.login() # user anonymous, passwd anonymous
ftp.retrlines('LIST') # list directory contents.....

Apr 8 '06 #1
1 1354
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
Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Vieths | last post: by
5 posts views Thread by Zhang Weiwu | last post: by
6 posts views Thread by =?Utf-8?B?bGlhbnF0bGl0?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.