Curl使用詳解(六)
31 TELNET遠端登入
The curl telnet support is basic and very easy to use. Curl passes all data passed to it on stdin to the remote server. Connect to a remote telnet server using a command line similar to: curl只支援基本的、非常簡單的telnert操作。curl將標準輸入的內容全部發送到遠端伺服器。連線到遠端telnet伺服器使用以下命令:
curl telnet://remote.server.com
And enter the data to pass to the server on stdin. The result will be sent to stdout or to the file you specify with -o. 然後將在標準輸入中輸入的資料傳送至伺服器。執行結果將被髮送至標準輸出,如果你希望將執行結果儲存至檔案,請使用引數-o。
You might want the -N/–no-buffer option to switch off the buffered output for slow connections or similar. 針對低速網路連線等情況,你也許通過引數-N/–no-buffer來關閉輸出快取。
Pass options to the telnet protocol negotiation, by using the -t option. To tell the server we use a vt100 terminal, try something like: 通過使用引數-t,可以向telnet傳送協議允許的選項。如果我們想告知伺服器將使用vt100終端 來進行連線,應輸入如下命令:
curl -tTTYPE=vt100 telnet://remote.server.com
Other interesting options for it -t include:對於-t, 其他有趣的選項還包括:
- XDISPLOC=<X display> Sets the X display location.
- NEW_ENV=<var,val> Sets an environment variable.
NOTE: The telnet protocol does not specify any way to login with a specified user and password so curl can’t do that automatically. To do that, you need to track when the login prompt is received and send the username and password accordingly. 注意:telnet協議沒有指定任何以指定使用者和密碼登入的方式,所以curl不能自動完成。要做到這一點,還需要跟蹤何時收到登入提示並相應地傳送使用者名稱和密碼。
32 PERSISTENT CONNECTIONS持久連線
Specifying multiple files on a single command line will make curl transfer all of them, one after the other in the specified order. 在一個命令中進行多個檔案將會讓curl按命令中指定的檔案順序一個接一個的傳輸所有的檔案。
libcurl will attempt to use persistent connections for the transfers so that the second transfer to the same host can use the same connection that was already initiated and was left open in the previous transfer. This greatly decreases connection time for all but the first transfer and it makes a far better use of the network. libcurl將會嘗試使用持久連線來傳輸全部檔案,這樣第二個檔案也可以使用已經完成初始化並仍舊對前一次傳輸開放的同一連線來進行傳輸。這樣將大幅度減少傳輸全部檔案所需的連線次數,對於網路的合理使用也大有好處。
Note that curl cannot use persistent connections for transfers that are used in subsequence curl invokes. Try to stuff as many URLs as possible on the same command line if they are using the same host, as that’ll make the transfers faster. If you use an HTTP proxy for file transfers, practically all transfers will be persistent. 注意:curl本身對於傳輸並不使用持久連線,傳輸的持久連線只是curl在隨後發起的庫呼叫。儘可能多的在一個命令列中使用大量的URL向同一伺服器傳輸檔案,這會裡整體的傳輸速度變得更快。實際 上,如果你使用HTTP代理來傳輸檔案,你就會發現所有的傳輸使用的都是持久連線。
33 MULTIPLE TRANSFERS WITH A SINGLE COMMAND LINE單條命令列下的多路傳輸
As is mentioned above, you can download multiple files with one command line by simply adding more URLs. If you want those to get saved to a local file instead of just printed to stdout, you need to add one save option for each URL you specify. Note that this also goes for the -O option (but not –remote-name-all). 根據上面內容提到的方法,通過簡單的新增多個URL,你可以在一個命令中下載多個檔案。如果你希望將這些檔案儲存到本地檔案中而不是列印輸出至標準輸出的話,你需要針對每個URL指定選項-O(而不需要使用–remote-name-all)
For example: get two files and use -O for the first and a custom file name for the second: 例如:下載二個檔案,對第一檔案使用-O,並自定義第二檔案的檔名:
curl -O http://url.com/file.txt ftp://ftp.com/moo.exe -o moo.jpg
You can also upload multiple files in a similar fashion: 你可以使用相似的模式來上傳多個檔案:
curl -T local1 ftp://ftp.com/moo.exe -T local2 ftp://ftp.com/moo2.txt
34 IPv6
curl will connect to a server with IPv6 when a host lookup returns an IPv6 address and fall back to IPv4 if the connection fails. The –ipv4 and –ipv6 options can specify which address to use when both are available. IPv6 addresses can also be specified directly in URLs using the syntax: 當使用IPv4進行連線失敗,並且伺服器返回的是一個IPv6地址的情況下,curl將使用IPv6連線伺服器。 選項–ipv4和–ipv6,可以在這二種地址都可用時指定使用哪種地址進行連線。IPv6地址還可以在URL中直接進行指定,具體方法如下:
http://[2001:1890:1112:1::20]/overview.html
When this style is used, the -g option must be given to stop curl from interpreting the square brackets as special globbing characters. Link local and site local addresses including a scope identifier, such as fe80::1234%1, may also be used, but the scope portion must be numeric or match an existing network interface on Linux and the percent character must be URL escaped. The previous example in an SFTP URL might look like: 使用這種格式時,必須同時指定選項-g,否則curl將認為[]是全域性字元,而匯入停止執行命令。 本地連結和本地站點地址包含一個識別符號範圍,如fe80::1234%1,這些識別符號也有可能被用到,但是其中一部分必須是數字或者匹配在linux系統中已經存在的網路介面卡,並且百分號必須被URL轉義。上一個例子中內容轉換成SFTP URL將會是下面的樣子:
sftp://[fe80::1234%251]/
IPv6 addresses provided other than in URLs (e.g. to the –proxy, –interface or –ftp-port options) should not be URL encoded. IPv6地址在URL以外提供的選項不應該編碼為URL,如:–proxy, –interface、–ftp-port。
35 METALINK賬號
Curl supports Metalink (both version 3 and 4 (RFC 5854) are supported), a way to list multiple URIs and hashes for a file. Curl will make use of the mirrors listed within for failover if there are errors (such as the file or server not being available). It will also verify the hash of the file after the download completes. The Metalink file itself is downloaded and processed in memory and not stored in the local file system. curl支援Metalink,包括version 3 和 4 (RFC 5854),一種可以列出多個URI資源並針對檔案可以進行hash的方法。如果出現無法獲取檔案或者無法連線伺服器等錯誤,curl將會把備用資源列表中資源做為映象來使用。並且在下載完成之後,還會對檔案進行hash校驗。Metalink檔案會在記憶體中完成上述的下載和處理工作,並不會將它們儲存的本地檔案系統中。
Example to use a remote Metalink file: 例如使用遠端Metalink檔案:
curl --metalink http://www.example.com/example.metalink
To use a Metalink file in the local file system, use FILE protocol (file://):
curl --metalink file://example.metalink
Please note that if FILE protocol is disabled, there is no way to use a local Metalink file at the time of this writing. Also note that if –metalink and –include are used together, –include will be ignored. This is because including headers in the response will break Metalink parser and if the headers are included in the file described in Metalink file, hash check will fail.
36 MAILING LISTS郵件列表
For your convenience, we have several open mailing lists to discuss curl, its development and things relevant to this. Get all info at https://curl.haxx.se/mail/. Some of the lists available are: 為了方便討論curl、軟體的開發以及與其相關的事宜,我們為您開放一了些郵件列表。你可以在如下網址獲得相關資訊https://curl.haxx.se/mail/。其中一些郵件列表為:
curl-users
Users of the command line tool. How to use it, what doesn’t work, new features, related tools, questions, news, installations, compilations,running, porting etc. 針對命令列工具的使用者。討論的內容包括:如何使用curl,軟體工作異常,新功能,相關工具,使用中遇到的問題,新聞,安裝,編譯,執行,埠等等。
curl-library
Developers using or developing libcurl. Bugs, extensions, improvements. 開發者使用或者開發libcurl,包括:Bugs,擴充套件,改進。
curl-announce
Low-traffic. Only receives announcements of new public versions. At worst, that makes something like one or two mails per month, but usually only one mail every second month. 郵件量很少。只接受公佈新版本的通知。最多每月傳送一至二封郵件,通常情況下,每二個月只發送一封郵件。
curl-and-php
Using the curl functions in PHP. Everything curl with a PHP angle. Or PHP with a curl angle. 用curl的函式應用於PHP, 包括所有curl與PHP相關的內容。
curl-and-python
Python hackers using curl with or without the python binding pycurl. 用於反饋Python駭客在繫結pycurl的情況下,無論是否在python環境下使用curl遇到的問題。
Please direct curl questions, feature requests and trouble reports to one of these mailing lists instead of mailing any individual. 請直接反饋curl的問題,功能性要求和故障報告到以上郵件列表中,而不要傳送私人郵件。