users of pycurl here?

  • Thread starter Michele Simionato
  • Start date
M

Michele Simionato

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
 
F

Fredrik Lundh

Michele said:
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>
 
M

Michele Simionato

The said:
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
 
F

Fredrik Lundh

Michele said:
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>
 
M

Michele Simionato

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

Michele Simionato
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top