473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ftp connection and commands (directroy size, etc)

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
Apr 12 '06 #1
3 5395
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

Apr 12 '06 #2
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
Apr 13 '06 #3
Hi Arne

On 2006-04-12 18:05, Arne wrote:
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
Apr 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: charliewest | last post by:
I have developed an application for WM 2003, which frequently transacts with a sql server ce 2.0 database. I have several procedures which utilize the following code: cn = new...
4
by: Mark | last post by:
OK. Here we go. I have an ASP.NET application that does many hits to a SQL Server DB on a separate server. When I first created this application (2 years ago) and was very new to ASP/ASP.NET, to...
8
by: Joanna Carter [TeamB] | last post by:
Hi Folks I am just trying to get my head around whether I can use a single SQLConnection for the life of the application or whether I should create it only when needed. I want to create...
16
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
1
by: rhyme2ri2 | last post by:
Hi all, Whenever i try to use 'quote nlst' or 'quote list' in ftp. It gives me this error 425:Can't establish connection. Connection refused'. It works fine when I use ls or dir commands. But I...
7
by: =?Utf-8?B?Sm9obiBTdGFnZ3M=?= | last post by:
Hello, Please read this all before giving an answer :) I'm doing some troubleshooting on a web application that my company wrote. It's written in asp.net 1.1. The error that the Event viewer...
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.