我试图在服务器(“我的服务器”)上编写Bash脚本,该脚本将从一台远程服务器(“源”)获取文件并将其复制到Dropbox帐户(“目标”)。我需要通过SFTP从Source获取文件,并将使用Dropbox API(HTTPS)将其复制到Destination。到目前为止,我可以通过以下方式获取文件:
curl -k "sftp://Source/file.txt" --user "me:mypasswd" -o "/test/file.txt" --ftp-create-dirs
,然后使用
将其复制到Dropboxcurl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer " \
--header "Dropbox-API-Arg: {\"path\": \"/path/to/file.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @/test/file.txt
我猜想这样做的“正确”方法是将文件从Source直接传送到Destination,但是我不确定如何将它们放在一起。
这绝对不是我的专业领域,所以我什至不知道从哪里开始-嵌套的CURL调用?如果有人能指出正确的方向,我将不胜感激。
更新
这是我正在运行的整个curl
命令:
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer $token" \
--header "Dropbox-API-Arg: {\"path\": \"/xfer/chef.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary "$(curl -k "http://marketing.dave0112.com/file.txt" --user "me:mypasswd")"
我遇到了不支持SFTP的CURL的问题,因此当我解决了这一问题时,我改用了HTTP。不知道这是否会影响任何事情。
答案 0 :(得分:1)
您可以替换此行:
--data-binary @/test/file.txt
使用
--data-binary @<(curl -k "sftp://Source/file.txt" --user "me:mypasswd")
如果有问题,请尝试:
--data-binary "$(curl -k "sftp://Source/file.txt" --user "me:mypasswd")"