ftp connection and commands (directroy size, etc)

A

Arne

Hello everybody!

I am working on Windows XP and I want to do the following:

1. Connecting to a server using ftp
2. Getting the directory structure and the size of each directory in the
root
3. Getting the owner of a file

All these steps I want to do with python. What I already have is:

1. Connecting to ftp

import ftplib
ftp = ftplib.FTP('host')
ftp.login(')
directory = '/'
ftp.cwd(directory)
linelist = []
ftp.retrlines('LIST', linelist.append)
ftp.close()

2. Getting the directory structure and the size of each directory in the
root

But I am don't know how to send commands to ftp and capturing the result
If have tried:
a = []
a=ftp.sendcmd('Dir')
By trying to get the directory with 'dir', I am getting an Error 500
result.

Furthermore I don't know how to get the directory size. Even I don't know
the best command for it.

3. Getting the owner of a file

Can I get the owner for one file? I know with the LIST you get them all.

Please be so kind and post a little bit of a solution code

Thank you very much!
Arne
 
M

maxou

Hello Arne
1. Connecting to ftp is OK
2. Getting the directory structure and the size of each directory in the
root

-If you want to get the structure of your directory you can simply do
this:

print ftp.dir(path_of_your_directory)
or by creating a list do this
a=ftp.dir(path_of_your_directory)
print a

- To get the size do this:

import os.path
size_directory=os.path.getsize(name_of_directory)
or
size_file=os.path.getsize(name_of_file)


Max
 
F

Fulvio

Alle 00:05, giovedì 13 aprile 2006, Arne ha scritto:
a=ftp.sendcmd('Dir')
By trying to get the directory with 'dir'

Are you sure that the command 'dir" is understood via ftp?
IF I'm not wrong would be 'ls' o list. But since I don't have such psckage on
my system, it's recommended you read the manual of that or
read here:

http://www.cs.colostate.edu/helpdocs/ftp.html

Which is the result of google search of "ftp command list" (no quote).

F
 
S

Stefan Schwarzer

Hi Arne

I am working on Windows XP and I want to do the following:

1. Connecting to a server using ftp
2. Getting the directory structure and the size of each directory in the
root
3. Getting the owner of a file

All these steps I want to do with python. What I already have is:
[...]
Please be so kind and post a little bit of a solution code

You should be able to do this with the ftputil library, at
http://ftputil.sschwarzer.net/ ;-) If you encounter any problems,
send a mail to the ftputil mailing list (see
http://ftputil.sschwarzer.net/trac/wiki/MailingList ) or to me.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top