【问题标题】:file transfer from 1 remote server to another remote server without downloading file文件从一台远程服务器传输到另一台远程服务器而不下载文件
【发布时间】:2020-05-04 15:15:44
【问题描述】:

我正在尝试在我的服务器(我的服务器)上编写一个 Bash 脚本,该脚本将从一个远程服务器(源)获取文件并将其复制到 Dropbox 帐户(目标)。我需要通过 SFTP 从 Source 获取文件,并将使用 Dropbox API (HTTPS) 将其复制到 Destination。到目前为止,我可以通过以下方式获取文件:

curl  -k "sftp://Source/file.txt" --user "me:mypasswd" -o "/test/file.txt" --ftp-create-dirs 

然后使用

将其复制到 Dropbox
curl -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

我猜测这样做的“正确”方法是将文件从源直接传输到目标,但我只是不确定如何将它们放在一起。

这绝对不是我的专业领域,所以我什至不知道从哪里开始 - 嵌套 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")"

我遇到了 CURL 不支持 SFTP 的问题,所以我在解决这个问题时更改为 HTTP。不确定这是否会影响任何事情。

【问题讨论】:

    标签: bash curl sftp file-transfer remote-server


    【解决方案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")"
    

    【讨论】:

    • 这会在 Destination 上创建新文件,但它是空的,并返回 curl: (23) Failed writing body。有什么解决这个问题的建议吗?
    • 已更新,请重试。
    • tis 还会创建一个空文件,并在终端中返回以下错误消息:--data-binary: command not found
    • 刚刚添加到 OP
    • uuuugh...这是嵌套的双引号...将内部引号更改为单引号,现在可以使用。谢谢!!
    猜你喜欢
    • 2016-05-03
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 2022-11-05
    相关资源
    最近更新 更多