cURL (pycurl) 通过 HTTP 代理的 FTP

发布于 2025-01-03 04:19:05 字数 1805 浏览 0 评论 0原文

我编写了简单的上传脚本,然后发现了下一件事: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌︼了一个春 2025-01-10 04:19:05

这是适合我的格式。

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

我花了很多时间来研究这些参数,如果您有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.

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

他不在意 2025-01-10 04:19:05

ftp上传的语法为:

curl -u "[email protected] Proxy-Username:Remote-Pass"     --ftp-account Proxy-Password --upload-file local-file     ftp://my-ftp.proxy.server:21/remote/upload/path/

The syntax for ftp upload is:

curl -u "[email protected] Proxy-Username:Remote-Pass"     --ftp-account Proxy-Password --upload-file local-file     ftp://my-ftp.proxy.server:21/remote/upload/path/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文