Daveh0
Daveh0

Reputation: 990

file transfer from 1 remote server to another remote server without downloading file

I am trying to write a Bash script on my server (My Server) that will grab a file from one remote server (Source) and copy it to a Dropbox account (Destination). I need to get the file from Source via SFTP and will be copying it to Destination using the Dropbox API (HTTPS). So far I can get the file with:

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

and then copy it to Dropbox with

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

I'm guessing the "right" way to do this is to pipe the file from Source directly to Destination, but I'm just not sure how to go about putting them together.

This is definitely not my area of expertise, so I don't even know where to start - nested CURL calls? If anyone could point me in the right direction, I'd be most appreciative.


UPDATE
Here's the whole curl command I'm running:

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")"

I was having issues with CURL not supporting SFTP so I changed to HTTP while i get that end sorted out. Not sure if that affects anything.

Upvotes: 0

Views: 1791

Answers (1)

Philippe
Philippe

Reputation: 26467

You can replace this line :

--data-binary @/test/file.txt

with

--data-binary @<(curl  -k "sftp://Source/file.txt" --user "me:mypasswd")

If problems, try :

--data-binary "$(curl  -k "sftp://Source/file.txt" --user "me:mypasswd")"

Upvotes: 1

Related Questions