ftp connection and commands (directroy size, etc)

Arne arne.meissner at gmx.de
Wed Apr 12 12:05:11 EDT 2006


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





More information about the Python-list mailing list