URL 回傳以逗號分隔的檔案串列示例
網址:http ://sometimesdownload.com/list_of_files
獲取檔案串列
curl -0 http://sometimesdownload.com/list_of_files
上述 curl 命令/串列的輸出回傳:
["file1.csv","file2.csv","file3.csv"...."filen.csv"]
如何一次運行將所有檔案下載到linux中/tmp/downloaded_files目錄下的指定路徑,下載后洗掉檔案。檔案的檔案名應與原始檔案相同。
CURL GET獲取檔案,下載檔案,然后在下載后使用CURL DELETE洗掉檔案。
檔案可以這樣下載:
http://sometimesdownload.com/list_of_files/file_name
例子:
curl -o http://sometimesdownload.com/list_of_files/file1.csv
curl -o http://sometimesdownload.com/list_of_files/file2.csv
curl -o http://sometimesdownload.com/list_of_files/file3.csv
謝謝
uj5u.com熱心網友回復:
您可以在沒有 curl 的情況下在 Java 中執行此操作,但如果您想使用 curl,您將需要使用 Runnable.exec 或 ProcessBuilder。有關示例,請參見使用空格將多個引數傳遞給 ProcessBuilder
uj5u.com熱心網友回復:
這可以像這樣完成
for i in $(curl http://sometimesdownload.com/list_of_files | jq -c '.[]'); then
# GET file
curl -O --output-dir /tmp/downloaded_files http://sometimesdownload.com/"$i"
# DELETE file
# However this is mostly not working straightforward and need tuning
# as no enough information here about how the files are hosted and
# configured by the remote server
curl -X DELETE http://sometimesdownload.com/"$i"
done
-cjq是從 json 陣列獲取計劃文本輸出的緊湊輸出選項。
$ echo '["file1.csv","file2.csv","file3.csv"]' | jq -c '.[]'
"file1.csv"
"file2.csv"
"file3.csv"
uj5u.com熱心網友回復:
您可以使用以下腳本。由于 BASH 中的串列語法不同,因此您必須轉換為 bash 語法。[abc,bca] 到 (abc bca)
然后你可以一個一個地拋出檔案并通過 CURL 下載。
這是示例腳本,我相信您可以根據您的環境對其進行更正。
bashParse() {
listData=$1
#validateData
finalData=()
echo ${listData} | grep ^"\[" > /dev/null && beginScope=0 || beginScope=1
echo ${listData} | grep "\]$" > /dev/null && endScope=0 || endScope=1
# build our List BASH stntax
if [ $beginScope -eq 0 ] && [ $endScope -eq 0 ] ; then
# Here I will remove [ and ], also replace last SPACE with nothing => sed
declare -a finalData=($(echo $listData|tr '\"' ' '| tr -d '[]'| tr ',' ' '))
fi
# Download files one by one by CURL
for i in "${finalData[@]}" ; do
echo "curl://<link>/$i"
done
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/512914.html
標籤:爪哇linux重击壳卷曲
