cURL (pycurl) 通过 HTTP 代理的 FTP
我编写了简单的上传脚本,然后发现了下一件事:curl 尝试在 ftp 服务器上执行 PUT:
简化的代码:
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()
几乎相同的代码几个月前运行良好,但是:
* 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
当我尝试从 shell 执行此操作时,得到相同的响应:
curl --upload-file "asus.c" --proxy 10.0.0.35:3128 \
--proxytunnel -u username:password ftp://<ftp_name>/asus.c
为什么?我错过了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是适合我的格式。
我花了很多时间来研究这些参数,如果您有curl as ftp问题,请告诉我。
以下是一些相关参数:
-U 或 --proxy-user
如果您需要代理凭证-u 或 --user
> 如果您有远程 ftp 用户名和密码--proxy-digest
如果您的代理使用摘要身份验证--proxy-basic
如果您的代理使用 basic身份验证--proxy-anyauth
如果您想取消代理身份验证-l 或 --list-only
如果您只想列出 FTP 目录。--digest
使用摘要身份验证的远程 ftp--basic
使用基本身份验证的远程 ftp-3 或 --sslv3
(SSL) 强制使用curl SSL 版本 3 与远程 ssl 服务器连接时-p 或 --proxytunnel
如果您有-x 或 --proxy
此选项将导致非 http 协议尝试建立隧道通过代理而不是仅仅使用它可以执行类似 http 的操作。-v 或 --verbose
如果您需要详细--ftp-ssl
Here is the format working for me.
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
ftp上传的语法为:
The syntax for ftp upload is: