2017-11-20 34 views
1

PythonでHTTP経由でFTP URLを取得する必要があります。私は、HTMLページとして宛先FTPリストを返すHTTPプロキシ経由でそうする必要があります。HTTP経由でPythonでHTTPプロキシ経由でFTP URLを取得する

Requestsとftplibを試しましたが、どちらもプロトコルを見て、HTTPプロキシではなくFTPプロキシを使用しようとしています。

私は、提供されたURLのプロトコルを無視し、要求されたURLをHTTP GET経由でHTTPプロキシサーバーに渡す必要があります。

は、ここで私はPythonで再現しようとしている例wgetのセッションです:

Connecting to PROXY connected. 
Created socket 3. 
Releasing 0x000055f4bc243ed0 (new refcount 1). 

---request begin--- 
GET ftp://ftp.mcafee.com/commonupdater/current/vscandat1000/dat/0000/ HTTP/1.1 
User-Agent: Wget/1.19.2 (linux-gnu) 
Accept: */* 
Accept-Encoding: gzip 
Host: ftp.mcafee.com 
Connection: Keep-Alive 
Proxy-Connection: Keep-Alive 

---request end--- 
Proxy request sent, awaiting response... 
---response begin--- 
HTTP/1.1 200 OK 
Via: 1.1 XXX.XXX.XXX.XXX 
Content-Type: text/html; charset=utf-8 
Content-Length: 20494 
Proxy-Connection: Keep-Alive 

---response end--- 
200 OK 
Registered socket 3 for persistent reuse. 
URI content encoding = ‘utf-8’ 
Length: 20494 (20K) [text/html] 
Saving to: ‘index.html’ 
+0

プロキシにプレーンソケットを開いてHTTPリクエストを送信することを検討しましたか? –

答えて

1

httplibを使用して、あなたがプロトコルに関係なく、任意のURLのプロキシを介したHTTP接続を強制することができます。

conn = httplib.HTTPConnection(proxy_host, proxy_port) 
conn.request("GET", ftp_url) 
resp = conn.getresponse() 
body = resp.read() 
関連する問題