473,382 Members | 1,657 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,382 software developers and data experts.

users of pycurl here?

I am having a hard time in finding out how to retrieve information
about
the *size* of files I want to download from an FTP site. Should I
send a QUOTE SIZE command to the ftp server or is there an easier way?
TIA,

Michele Simionato

Oct 7 '05 #1
4 1634
Michele Simionato wrote:
I am having a hard time in finding out how to retrieve information
about the *size* of files I want to download from an FTP site. Should I
send a QUOTE SIZE command to the ftp server or is there an easier way?


SIZE isn't a standard FTP command, so that only works for some servers.

if you want your code to work for a wider range of servers, you need to
parse the output from the LIST command:

http://cr.yp.to/ftp/list.html

here's a robust parser for various LIST output formats:

http://cr.yp.to/ftpparse.html

(google for "ftpparse" to find python bindings for that module)

</F>

Oct 7 '05 #2
The Effbot wrote:
here's a robust parser for various LIST output formats:

http://cr.yp.to/ftpparse.html

(google for "ftpparse" to find python bindings for that module)


Well, I have downloaded the one from your site (ftpparse-1.1-20021124)
and I have given a python setup.py install. Now I have a _ftpparse.so
which exposes a single function 'parse'. However both the module and
the function do not have any docstring, the underscore makes me
believe that there should be a ftpparse.py file which is missing,
and the README says "for a usage example, see the sanity.py test
script" but there is not such a script in the distribution :-(

Michele Simionato

Oct 10 '05 #3
Michele Simionato wrote:
the README says "for a usage example, see the sanity.py test
script" but there is not such a script in the distribution :-(


looks like a distutils glitch... try this one:

# $Id$
# minimal sanity check

import string

TESTS = [
"# examples taken from ftpparse.c",
"+i8388621.29609,m824255902,/,\tdev",
"+i8388621.44468,m839956783,r,s10376,\tRFCEPLF ",
"-rw-r--r-- 1 root other 531 Jan 29 03:26 README",
"dr-xr-xr-x 2 root other 512 Apr 8 1994 etc",
"dr-xr-xr-x 2 root 512 Apr 8 1994 etc",
"lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin",
"04-27-00 09:09PM <DIR> licensed",
"07-18-00 10:16AM <DIR> pub",
"04-14-00 03:47PM 589 readme.htm",
]

import _ftpparse

# parse sample strings
for line in TESTS:
print repr(line), "->"
try:
item = _ftpparse.parse(line)
except ValueError:
print "***", "cannot parse this line"
else:
print " ", (item.name, item.size, item.mtime, item.id, item.trycwd)

# check behaviour for unknown attributes
try:
item.unknown
except AttributeError:
pass

# end

on my machine, this prints:

'# examples taken from ftpparse.c' ->
*** cannot parse this line
'+i8388621.29609,m824255902,/,\tdev' ->
('dev', None, 824255902, '8388621.29609', True)
'+i8388621.44468,m839956783,r,s10376,\tRFCEPLF' ->
('RFCEPLF', 10376, 839956783, '8388621.44468', False)
'-rw-r--r-- 1 root other 531 Jan 29 03:26 README' ->
('README', 531, 1106969160, None, False)
'dr-xr-xr-x 2 root other 512 Apr 8 1994 etc' ->
('etc', 512, 765763200, None, True)
'dr-xr-xr-x 2 root 512 Apr 8 1994 etc' ->
('etc', 512, 765763200, None, True)
'lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin' ->
('bin', 7, 1106612220, None, True)
'04-27-00 09:09PM <DIR> licensed' ->
('licensed', None, 956869740, None, True)
'07-18-00 10:16AM <DIR> pub' ->
('pub', None, 963915360, None, True)
'04-14-00 03:47PM 589 readme.htm' ->
('readme.htm', 589, 955727220, None, False)

</F>

Oct 10 '05 #4
Yes, it works fine, thanks (still I am a bit surprised there is not
ftpparse.py but only
an _ftpparse.so).

Michele Simionato

Oct 10 '05 #5

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

Similar topics

1
by: Mark Ferguson | last post by:
I've been trying to get a simple pycurl script working with an authenticating proxy, here is the code (with changes to protect the guilty!): from pycurl import * import StringIO b =...
1
by: Ju Hui | last post by:
I download it from http://pycurl.sourceforge.net/ and then extract it to D:\usr\pycurl-7.15.2 then D:\usr\pycurl-7.15.2>setup.py install --curl-dir=d:\usr\pycurl-7.15.2 Using curl directory:...
4
by: Ju Hui | last post by:
import pycurl c = pycurl.Curl() c.setopt( pycurl.URL, 'http://www.test.com/test.html' ) import StringIO b = StringIO.StringIO() c.setopt( c.WRITEFUNCTION, b.write ) c.setopt( c.FOLLOWLOCATION,...
0
by: Chaos | last post by:
For the Program I Am Making I Make Multiple HTTP Request to My Server. I found that using urllib2 it was pretty slow, when I activated the program and tested it it would hang from 2secs-5secs since...
1
by: pabloski | last post by:
Hi to all, I have a problem with a snippet of code that creates a Curl object the code is c = pycurl.Curl() c.key = keyCurrent c.proxy = proxyCurrent c.url = "http://www.google." + lg +...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.