
我正在開發一種工具來獲取隱藏在遠端系統上一個非常大的檔案中的一些資料。複製整個檔案是不切實際的,而且我需要的所有資料都存在於檔案的前 1000 個位元組左右。我知道我可以開始獲取並使用 ^C 取消它以獲取部分文件,但是這將很難(如果不是不可能)以任何一致性實現自動化。
我想告訴我的 ftp 客戶端僅獲取遠端檔案的 x 個位元組,並在獲取後立即退出。我發現一些 Windows 用戶端可以進行部分下載,但我沒有在 ftp 手冊頁中找到任何內容,而且線上文件也很少。
我找到了這個方法:http://cdsarc.u-strasbg.fr/doc/ftp.htx這表示以下語法:
ftp> get bigfile.dat:0-5000 bigfile.nxt
我不清楚這是否應該在客戶端或伺服器中實現,但無論哪種情況,它似乎都不適用於我的環境。 (連接到 z/OS 上執行的 FTP 伺服器的標準 Linux ftp 用戶端)
即使在 Linux 標準 ftp 用戶端和 Windows 上的 filezilla 伺服器之間嘗試時,我的嘗試也會以以下方式失敗
ftp> get green.gif:0-10c
local: green.gif:0-10c remote: green.gif:0-10c
227 Entering Passive Mode (9,42,91,226,4,105)
550 File not found
因此 :0-10c 似乎被解釋為檔案名稱的一部分。失敗。有什麼想法嗎?
答案1
使用捲曲。從手冊頁:
-r/--range <range>
(HTTP/FTP/FILE) Retrieve a byte range (i.e a partial document)
from a HTTP/1.1, FTP server or a local FILE. Ranges can be spec-
ified in a number of ways.
0-499 specifies the first 500 bytes
500-999 specifies the second 500 bytes
-500 specifies the last 500 bytes
9500- specifies the bytes from offset 9500 and forward
0-0,-1 specifies the first and last byte only(*)(H)
500-700,600-799
specifies 300 bytes from offset 500(H)
但是,請注意,伺服器必須支援 SIZE 擴充功能才能使其正常運作。
答案2
我想你想為此使用curl
從手冊頁:
-r/--range <range>
(HTTP/FTP/FILE) Retrieve a byte range (i.e a partial document)
from a HTTP/1.1, FTP server or a local FILE. Ranges can be spec‐
ified in a number of ways.
0-499 specifies the first 500 bytes
500-999 specifies the second 500 bytes
-500 specifies the last 500 bytes
9500- specifies the bytes from offset 9500 and forward
答案3
像這樣的方案很大程度取決於伺服器的實作。有些伺服器比其他伺服器支援更多的功能。
我會研究某種分割檔案的方法,或考慮使用自訂應用程式來發送您要求的範圍。