curl-and-python

Re: Pycurl and FTP

From: Shailesh Kumar <shaileshk_at_gmail.com>
Date: Fri, 11 Jun 2010 23:21:48 +0530

import pycurl
import StringIO
# lets create a pycurl object
c = pycurl.Curl()
# lets specify the details of FTP server
c.setopt(pycurl.URL, r'ftp://ftp.ncbi.nih.gov/refseq/release/')
# lets create a buffer in which we will write the output
output = StringIO.StringIO()
# lets assign this buffer to pycurl object
c.setopt(pycurl.WRITEFUNCTION, output.write)
# lets perform the LIST operation
c.perform()
# lets get the output in a string
result = output.getvalue()
# lets print the string on screen
print result
# FTP LIST output is separated by \r\n
# lets split the output in lines
lines = result.split('\r\n')
# lets print the number of lines
print len(lines)
# lets walk through each line
for line in lines:
    # lets print each part separately
    parts = line.split()
    # we can print the parts now
    print parts
    # the individual fields in this list of parts
    if not parts: continue
    permissions = parts[0]
    group = parts[2]
    user = parts[3]
    size = parts[4]
    month = parts[5]
    day = parts[6]
    yearortime = parts[7]
    name = parts[8]

On Fri, Jun 11, 2010 at 10:57 PM, James Webber <jamestwebber_at_gmail.com> wrote:
> Um. Can you get to that site through a browser? That site should be
> accessible anywhere, but maybe there's some network quirk preventing you
> from seeing it. You could try the FTP site that you're interested in,
> instead, and see if that works.
>
> If you can see the site otherwise, then maybe there is some problem with
> pycurl on your computer--but I don't have the foggiest what that might be,
> sorry.
>
> On Fri, Jun 11, 2010 at 1:01 PM, MARTIN Oliver <o.martin_at_wanadoo.fr> wrote:
>>
>> Hi,
>>
>> Thanks for your answers.
>>
>> When I try your code, I have no answer from python:
>>
>> >>> import pycurl
>> >>> crl = pycurl.Curl()
>> >>> crl.setopt(pycurl.URL, r'ftp://ftp.ncbi.nih.gov/refseq/release/')
>> >>> crl.perform()
>> >>>
>>
>> I don't understand why.
>>
>> I had tried this code before, and as I had no answer, I've posted here.
>>
>> If anyone can help me ...
>>
>> 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