cURL (pycurl) FTP over HTTP proxy

13,616

Here is the format working for me.

curl --user 'ftp_user:ftp_password' --disable-epsv --proxytunnel -x 'yourproxy.com:port' -T 'your.localfile' 'ftp://remote.ftp.org:port/path' -v

I spent a lot of time to struggle with those parameters, let me know if you have curl as ftp problem.

Here is some parameter related:

-U or --proxy-user <proxy_user:proxy_password> if you need proxy credential

-u or --user <ftp_user:ftp_password> if you have remote ftp username and password

--proxy-digest if your proxy use digest authentication

--proxy-basic if your proxy use basic authentication

--proxy-anyauth if you want to detech proxy authentication

-l or --list-only if you only want to list an FTP directory.

--digest remote ftp using digest authentication

--basic remote ftp using basic authentication

-3 or --sslv3 (SSL) Forces curl to use SSL version 3 when connect with remote ssl server

-p or --proxytunnel if you have -x or --proxy this option will cause non-http protocols to attempt to tunnel through the proxy instead of merely using it to do http-like operations.

-v or --verbose if you need verbose

--ftp-ssl

Share:
13,616

Related videos on Youtube

mik_os
Author by

mik_os

Updated on June 04, 2022

Comments

  • mik_os
    mik_os almost 2 years

    I writing simple uploading script and just catched next thing: curl tries to do PUT on a ftp server:

    The simplified code:

    import pycurl
    from os.path import getsize
    
    c = pycurl.Curl()
    c.setopt(pycurl.URL, 'ftp://<ftp_name>:21/asus.c')
    c.setopt(pycurl.USERPWD, 'username:password')
    c.setopt(pycurl.PROXY, '10.0.0.35')
    c.setopt(pycurl.PROXYPORT, 3128)
    c.setopt(pycurl.VERBOSE, 1)
    f = open('asus.c')
    c.setopt(pycurl.INFILE, f)
    c.setopt(pycurl.INFILESIZE, getsize('asus.c'))
    c.setopt(pycurl.HTTPPROXYTUNNEL, 1)
    c.setopt(pycurl.UPLOAD, 1)
    c.perform()
    

    Almost same code worked well few month ago, but:

    * About to connect() to proxy <IP> port 3128 (#0)
    *   Trying <IP>... * connected
    * Connected to <IP> (<IP>) port 3128 (#0)
    * Establish HTTP proxy tunnel to <ftp_name>:21
    * Server auth using Basic with user 'username'
    > CONNECT <ftp_name>:21 HTTP/1.1
    Host: <ftp_name>:21
    User-Agent: PycURL/7.21.6
    Proxy-Connection: Keep-Alive
    
    < HTTP/1.0 200 Connection established
    < 
    * Proxy replied OK to CONNECT request
    * Server auth using Basic with user 'username'
    > PUT /asus.c HTTP/1.1
    Authorization: Basic _______________________________
    User-Agent: PycURL/7.21.6
    Host: <ftp_name>:21
    Accept: */*
    Content-Length: 2627
    Expect: 100-continue
    
    220 ProFTPD 1.3.3 Server (______ FTP Server) [<IP>]
    500 PUT not understood
    500 AUTHORIZATION: not understood
    500 USER-AGENT: not understood
    500 HOST: not understood
    500 ACCEPT: not understood
    500 CONTENT-LENGTH: not understood
    500 EXPECT: not understood
    500 Invalid command: try being more creative
    

    And same response when I try to do this from shell:

    curl --upload-file "asus.c" --proxy 10.0.0.35:3128 \
    --proxytunnel -u username:password ftp://<ftp_name>/asus.c
    

    Why? What I missed?

    • 9000
      9000 over 12 years
      It looks like you're trying to talk HTTP to an FTP server. Does your proxy work as an FTP proxy with these settings, e.g. from a browser or a known FTP client?
    • mik_os
      mik_os over 12 years
      Yes. FileZilla connects (and uploads) fine through this proxy (it's a configured squid).
  • mik_os
    mik_os about 12 years
    The goal was to upload through http-proxy.