使用curl 將檔案和資料夾傳送到nextcloud / owncloud 公共共用資料夾的Bash 腳本。
邏輯是
cloudsend
起源就在這裡,感謝所有為原始 GIST 做出貢獻的人
另請檢查我的 cloudmanager 應用程式以取得完整的 nextcloud/owncloud webdav 用戶端。
Cloudsend v2 改變了密碼解析的工作方式。
Cloudsend 0.xx 使用-p
參數作為環境密碼(在 v2+ 中改為-e
)。
請使用-e
或-p
之一,但不能同時使用兩者。將使用最後一個被呼叫的。
Env Pass >設定變數CLOUDSEND_PASSWORD='MySecretPass'
並使用選項-e
Param Pass >使用-p
將密碼作為參數發送
您可以透過設定-g
選項來使用輸入通配符(通配符)。
這將忽略輸入檔檢查並將 glob 傳遞給curl以供使用。
通配時不得重新命名文件,將使用輸入檔名。
通配時不得發送資料夾,只允許傳送文件。
全域範例:
'{file1.txt,file2.txt,file3.txt}'
'img[1-100].png'
有關通配符的更多信息
https://github.com/tavinus/cloudsend.sh/wiki/Input-Globbing
您可以使用-
或 發送管道內容.
作為輸入檔名(curl 規格) 。
您必須設定目標檔案名稱以使用 stdin 作為輸入( -r
)。
來自curl的手冊:
使用檔案名稱-
(單一破折號)來使用 stdin 而不是給定檔案。
或者,檔名.
可以指定(單一句點)而不是-
來使用
stdin 處於非阻塞模式,允許在上傳 stdin 時讀取伺服器輸出。
從 v2.2.0 開始, cloudsend.sh
可以傳送資料夾。它將遍歷資料夾樹,創建
每個資料夾並發送每個文件。只需使用資料夾路徑作為輸入。
這將發送目前 shell 資料夾中的每個檔案。
更改第一個./
以更改輸入資料夾(例如'/home/myname/myfolder'
)
-maxdepth 1
將只讀取當前資料夾,更多級別會更深,抑制所有級別
尋找 ./ -maxdepth 1 -type f -exec ./cloudsend.sh {} https://cloud.mydomain.tld/s/TxWdsNX2Ln3X5kxG -p yourPassword ;
這將發送/home/myname/myfolder
內的每個文件,包括所有子資料夾。
尋找 /home/myname/myfolder -type f -exec ./cloudsend.sh {} https://cloud.mydomain.tld/s/TxWdsNX2Ln3X5kxG -p yourPassword ;
這會發送目前 shell 資料夾的 gzip 壓縮包。
tar cf - “$(pwd)”| gzip -9 -c | gzip -9 -c | ./cloudsend.sh - 'https://cloud.mydomain.tld/s/TxWdsNX2Ln3X5kxG' -r myfolder.tar.gz
這會發送/home/myname/myfolder
的 gzip 壓縮包。
tar cf - /home/我的名字/我的資料夾 | gzip -9 -c | gzip -9 -c | ./cloudsend.sh - 'https://cloud.mydomain.tld/s/TxWdsNX2Ln3X5kxG' -r myfolder.tar.gz
這將發送/home/myname/myfolder
的遞歸 zip 檔案。
zip -q -r -9 - /home/我的名字/我的資料夾 | ./cloudsend.sh - 'https://cloud.mydomain.tld/s/TxWdsNX2Ln3X5kxG' -r myfolder.zip
從版本 2.3.2 開始,您可以使用-C|--mkdir
參數在遠端伺服器中建立資料夾。它可以是單一資料夾或樹。
只需傳遞要建立的資料夾,就好像它是正在傳送的檔案一樣。
$ ./cloudsend.sh -C -p MyPassword 'A Folder' "https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY" Tavinus Cloud Sender v2.3.5 > Color mode OFF > Using password from Parameter > Makedir mode is ON ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ CREATING FOLDERS ON TARGET ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ A Folder > OK (created) ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ MAIN TARGET DOWNLOAD URL ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ Download URL: > https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY/download?path=/A Folder https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY/download?path=%2fA%20Folder Access URL: > https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=/A Folder https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=%2fA%20Folder ‗‗‗‗‗‗‗‗‗ SUMMARY ‾‾‾‾‾‾‾‾‾ Curl : NO Errors CurlExit : 0 WebDav : NO Errors Status : Makedir Completed Root : / Base : / Full : / Target : A Folder Type : Directory
從版本 2.3.1 開始,您可以刪除遠端伺服器上的檔案和資料夾。
只需使用選項-D|--delete
並傳遞要刪除的檔案/資料夾,就好像它是正在傳送的檔案一樣。
此範例從遠端伺服器刪除A Folder
及其所有子資料夾和檔案。
$ ./cloudsend.sh -D -p MyPassword 'A Folder' "https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY" Tavinus Cloud Sender v2.3.5 > Using password from Parameter > Delete mode is ON ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ DELETING TARGET ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ A Folder > OK (deleted) ‗‗‗‗‗‗‗‗‗ SUMMARY ‾‾‾‾‾‾‾‾‾ Curl : NO Errors CurlExit : 0 WebDav : NO Errors Status : Delete Completed Root : / Base : / Full : / Target : A Folder Type : Unknown
從版本 2.3.2 開始,您可以使用-T|--target
參數設定遠端操作的目標資料夾。它可以是單一資料夾或樹。
除非您正在執行刪除命令,否則將在執行作業之前建立目標樹。
所有命令都將使用目標資料夾作為基本資料夾(刪除、發送、建立資料夾等)。
$ ./cloudsend.sh -p MyPassword -T 'A Folder/ A Subfolder' ./README.md "https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY" Tavinus Cloud Sender v2.3.5 > Using password from Parameter > Base Target folder set to: "/A Folder/ A Subfolder" ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ CREATING BASE TARGET FOLDERS ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ A Folder > OK (created) A Folder/ A Subfolder > OK (created) ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ SENDING SINGLE FILE ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ README.md > ######################################################################### 100.0% ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ MAIN TARGET DOWNLOAD URL ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ Download URL: > https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY/download?path=A Folder/ A Subfolder&files=README.md https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY/download?path=A%20Folder%2f%20A%20Subfolder&files=README.md Access URL: > https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=A Folder/ A Subfolder&files=README.md https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=A%20Folder%2f%20A%20Subfolder&files=README.md ‗‗‗‗‗‗‗‗‗ SUMMARY ‾‾‾‾‾‾‾‾‾ Curl : NO Errors CurlExit : 0 WebDav : NO Errors Status : Send Completed Root : / Base : /A Folder/ A Subfolder Full : /A Folder/ A Subfolder Target : README.md Type : File
Cloudsend 也支援從 URL 讀取根資料夾(如果 URL 連結到資料夾)。
Cloudsend 不會嘗試建立此資料夾,它必須已經存在,但它會將其用作所有內容的基本根資料夾,包括基本--target
設定。
資料夾連結的語法為https://cloud.mydomain.tld/index.php/s/H2Q3RHXZ4f974sY?path=my root
。
?path=my root
將'my root'
定義為根目標資料夾。
在此範例中,「我的根」已存在於伺服器上,否則我們會收到錯誤
$ ./cloudsend.sh -p MyPass -T 'A Folder/A Subfolder' "../folder 1" "https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=my root" Tavinus Cloud Sender v2.3.6 > Using password from Parameter > Base Target folder set to: "/A Folder/A Subfolder" > Root Target folder set from URL: "my root" ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ CREATING BASE TARGET FOLDERS ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ A Folder > OK (created) A Folder/A Subfolder > OK (created) ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ CREATING FOLDER TREE AT DESTINATION ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ folder 1 > OK (created) folder 1/folder 1-a > OK (created) folder 1/folder 1-a/folder 1 a 1 > OK (created) folder 1/folder 1-b > OK (created) ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ SENDING ALL FILES FROM FOLDER TREE ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ folder 1/file 1.txt > ######################################################################### 100.0% folder 1/file 2.txt > ######################################################################### 100.0% folder 1/file 3.txt > ######################################################################### 100.0% folder 1/folder 1-a/file 2 3.txt > ######################################################################### 100.0% folder 1/folder 1-a/folder 1 a 1/file 6.txt > ######################################################################### 100.0% folder 1/folder 1-b/file 5.txt > ######################################################################### 100.0% ‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗ MAIN TARGET DOWNLOAD URL ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ Download URL: > https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY/download?path=my root/A Folder/A Subfolder/folder 1 https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY/download?path=my%20root%2fA%20Folder%2fA%20Subfolder%2ffolder%201 Access URL: > https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=my root/A Folder/A Subfolder/folder 1 https://cloud.mydomain.tld/index.php/s/H4Q3RHXZ4e974PY?path=my%20root%2fA%20Folder%2fA%20Subfolder%2ffolder%201 ‗‗‗‗‗‗‗‗‗ SUMMARY ‾‾‾‾‾‾‾‾‾ Curl : NO Errors CurlExit : 0 WebDav : NO Errors Status : Send Completed Root : /my root Base : /A Folder/A Subfolder Full : /my root/A Folder/A Subfolder Target : folder 1 Type : Directory
$ ./cloudsend --help Tavinus Cloud Sender v2.3.8 Parameters: -h | --help Print this help and exits -q | --quiet Disables verbose messages -V | --version Prints version and exits -N | --no-color Disables colored output -D | --delete Delete file/folder in remote share -T | --targetRebase work into a target folder (instead of root) -C | --mkdir Create a directory tree in the remote share -r | --rename Change the destination file name -g | --glob Disable input file checking to use curl globs -k | --insecure Uses curl with -k option (https insecure) -A | --user-agent Specify user agent to use with curl -A option -E | --referer Specify referer to use with curl -e option -l | --limit-rate Uses curl limit-rate (eg 100k, 1M) -a | --abort-on-errors Aborts on Webdav response errors -p | --password Uses as shared folder password -e | --envpass Uses env var $CLOUDSEND_PASSWORD as share password You can 'export CLOUDSEND_PASSWORD' at your system, or set it at the call Please remeber to also call -e to use the password set Use: ./cloudsend.sh [options] CLOUDSEND_PASSWORD='MySecretPass' ./cloudsend.sh -e [options] Passwords: Cloudsend 2 changed the way password works Cloudsend 0.x.x used the '-p' parameter for the Environment password (changed to -e in v2+) Please use EITHER -e OR -p, but not both. The last to be called will be used Env Pass > Set the variable CLOUDSEND_PASSWORD='MySecretPass' and use the option '-e' Param Pass > Send the password as a parameter with '-p ' Folders: Cloudsend 2.2.0 introduces folder tree sending. Just use a directory as . It will traverse all files and folders, create the needed folders and send all files. Each folder creation and file sending will require a curl call. Target Folder: Cloudsend 2.3.2 introduces the target folder setting. It will create the folder in the remote host and send all files and folders into it. It also works as a base folder for the other operations like deletion and folder creation. Accepts nested folders. ./cloudsend.sh -T 'f1/f2/f3' -p myPass 'folder|file' 'https://cloud.domain/index.php/s/vbi2za9esfrgvXC' Create Folder: Available since version 2.3.2. Just pass the folder name to be created as if it was the file/folder being sent and add the -C | --mkdir parameter. Runs recursively. ./cloudsend.sh -C -p myPass 'new folder/new2' 'https://cloud.domain/index.php/s/vbi2za9esfrgvXC' Delete: Available since version 2.3.1. Just pass the file/folder to be deleted as if it was the file/folder being sent and add the -D | --delete parameter. ./cloudsend.sh -D -p myPass 'folder/file' 'https://cloud.domain/index.php/s/vbi2za9esfrgvXC' Input Globbing: You can use input globbing (wildcards) by setting the -g option This will ignore input file checking and pass the glob to curl to be used You MUST NOT rename files when globbing, input file names will be used You MUST NOT send folders when globbing, only files are allowed Glob examples: '{file1.txt,file2.txt,file3.txt}' 'img[1-100].png' Send from stdin (pipe): You can send piped content by using - or . as the input file name (curl specs) You MUST set a destination file name to use stdin as input (-r ) Use the file name '-' (a single dash) to use stdin instead of a given file Alternately, the file name '.' (a single period) may be specified instead of '-' to use stdin in non-blocking mode to allow reading server output while stdin is being uploaded Examples: CLOUDSEND_PASSWORD='MySecretPass' ./cloudsend.sh -e './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' ./cloudsend.sh './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' ./cloudsend.sh 'my Folder' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' ./cloudsend.sh -r 'RenamedFile.txt' './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' ./cloudsend.sh --limit-rate 200K -p 'MySecretPass' './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' ./cloudsend.sh -p 'MySecretPass' -r 'RenamedFile.txt' './myfile.txt' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' ./cloudsend.sh -g -p 'MySecretPass' '{file1,file2,file3}' 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' cat file | ./cloudsend.sh - 'https://cloud.mydomain.net/s/fLDzToZF4MLvG28' -r destFileName
什麼是「https://cloud.mydomain.net/s/fLDzToZF4MLvG28」?
什麼是「資料夾連結」?
我從哪裡得到它?
特別是“s/fLDzToZF4MLvG28”部分?
您必須共享一個可寫資料夾並使用生成的鏈接
來自 Nextcloud 21 文檔