curl-and-python
Re: Pycurl and FTP
Date: Fri, 11 Jun 2010 20:21:07 +0530
Hi,
Just a remark on this. The response of FTP LIST command (like one
shown below) is very much non-standard. Different flavors of FTP
servers simply display the directory listing differently. So the
parsing of this output may be easy for one FTP server but a code for
parsing directory listings which works across all kinds of FTP servers
is difficult to write. This is probably the reason why this
functionality is not provided in ftplib (Python Standard Library). In
the FTP standard, the output of FTP LIST command was intended for
human consumption rather than computer interpretation which led to all
the variations over the years.
FTPPARSE http://cr.yp.to/ftpparse.html is a library for parsing FTP
LIST command responses for a variety of FTP servers. ftpparse
currently understands the LIST output from any UNIX server, Microsoft
FTP Service, Windows NT FTP Server, VMS, WFTPD, NetPresenz, NetWare,
and MSDOS. Its easy to write a Python wrapper for this library using
ctypes.
Even this library doesn't work for a number of situations:
- When the size of a file is bigger than 2 GB.
- FTP servers of various video servers (I have seen GUI FTP clients
like FileZilla or Windows explorer suck on some of them)
With regards,
- Shailesh
On Fri, Jun 11, 2010 at 7:01 PM, James Webber <jamestwebber_at_gmail.com> wrote:
> It's as simple as setting the pycurl URL to the FTP directory, and getting
> that page. I just tried this:
>
>>>> import pycurl
>>>> crl = pycurl.Curl()
>>>> crl.setopt(pycurl.URL, r'ftp://ftp.ncbi.nih.gov/refseq/release/')
>>>> crl.perform()
> -r--r--r-- 1 ftp anonymous 4444 Sep 16 2004 README
> dr-xr-xr-x 2 ftp anonymous 761856 May 19 14:10 complete
> dr-xr-xr-x 2 ftp anonymous 24576 May 19 14:12 fungi
> dr-xr-xr-x 2 ftp anonymous 49152 May 19 13:13 invertebrate
> dr-xr-xr-x 2 ftp anonymous 438272 May 19 12:55 microbial
> dr-xr-xr-x 2 ftp anonymous 4096 May 19 12:29 mitochondrion
> dr-xr-xr-x 2 ftp anonymous 12288 May 19 12:28 plant
> dr-xr-xr-x 2 ftp anonymous 4096 May 19 14:11 plasmid
> dr-xr-xr-x 2 ftp anonymous 4096 May 19 12:55 plastid
> dr-xr-xr-x 2 ftp anonymous 16384 May 19 13:09 protozoa
> dr-xr-xr-x 3 ftp anonymous 4096 May 19 14:12 release-catalog
> dr-xr-xr-x 3 ftp anonymous 4096 May 19 14:26 release-notes
> dr-xr-xr-x 3 ftp anonymous 4096 May 19 14:12 release-statistics
> dr-xr-xr-x 2 ftp anonymous 36864 May 19 13:07 vertebrate_mammalian
> dr-xr-xr-x 2 ftp anonymous 8192 May 19 12:31 vertebrate_other
> dr-xr-xr-x 2 ftp anonymous 4096 May 19 13:08 viral
>>>>
>
> Of course, you'd have to parse that result, but that shouldn't be too hard.
>
> - James
>
> On Fri, Jun 11, 2010 at 5:22 AM, MARTIN Oliver <o.martin_at_wanadoo.fr> wrote:
>>
>> Hi,
>>
>> I'm trying using Pycurl to connect to FTP.
>>
>> I need to list an FTP directory, dowload files from this directory and
>> erase files after download.
>>
>> I don't know how to get the content of the directory in a list.
>>
>> Does anyone can help me please? Or are there somewhere some source code
>> that could help me ?
>>
>> Thanks,
>>
>> Olivier
>>
>>
>>
>> _______________________________________________
>> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
>
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
>
>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2010-06-11