Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ftp putting information in a variable

Reply
Thread Tools

ftp putting information in a variable

 
 
Arne
Guest
Posts: n/a
 
      04-08-2006
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.....

 
Reply With Quote
 
 
 
 
Stefan Schwarzer
Guest
Posts: n/a
 
      04-11-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
putting information from iframe in hidden textfiel Madame Blablavatsky Javascript 1 09-01-2005 07:57 PM
Putting code in a variable and running interactively? Jimmy Phillips Perl 2 08-25-2004 04:49 PM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM
How to aviod putting url-information in history-list. Per-Olof Nilsson ASP General 3 02-12-2004 01:57 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57