How do I copy a file from one server to another without downloading first?

1

1

Is it possible to copy a file from one server to another without downloading first?

I have a backup file that is 10gb that I'm wanting to copy from my production server to my staging server.

Currently I'm just doing it through Transmit, but that downloads the file first, and then uploads it.

Is there a way to directly move the file from the production server to the staging server? Does SCP do this or does it download it first? How about rsync?

EDIT

Both are linux servers running Ubuntu 14.04 LTS.

Corey

Posted 2016-07-19T17:27:28.360

Reputation: 233

You are asking if SCP is a solution to your problem. Do you know what SCP stands for? You would typically make a connection to Server A from Server B to do what you describe. Since you provided zero information abot your server configuration its not possible to say if SCP or SFTP is even an option you can use. You should provide that information. – Ramhound – 2016-07-19T17:31:01.547

Answers

5

I'm presuming these are both linux servers as you've mentioned scp (yes I am aware scp exists for windows).

Simply ssh onto one of the servers, then scp the file directly to the other server.

scp file user@server:/location/

Infact, if your version of scp supports it (I've not used one that doesn't but the online man pages don't seem to document this feature) you can use -3 which will move a file between two hosts, via the local host.

scp -3 file user@server:/location/

This will use the local systems bandwidth, but it won't 'save' a copy of the file locally.

You could also use rsync to achieve the same, however the command is slightly different and I'm not versed well enough to know it off the top of my head.

djsmiley2k TMW

Posted 2016-07-19T17:27:28.360

Reputation: 5 937

This is already the default when scp user@server1:file user@server2:/location/ is used (unless -3 is also given). – user1686 – 2016-07-19T17:45:02.827

So SCP doesn't pass traffic through your local computer? Meaning, it doesn't download first? – Corey – 2016-07-19T17:46:45.717

1Not if you've already ssh'd into one of the servers. – djsmiley2k TMW – 2016-07-19T17:50:50.517

0

Hmm... ...From the sound of it, perhaps one of the systems is limited in some fashion, or maybe time is a factor. Short version: SCP is great for a one shot copy, with some caveats. I'll assume there are 3 servers involved here: Server A is the destination, server B is the remote location with the file, and server C is the machine you want to run the copy operation (C for copy). I would checksum the file on server B, then scp will copy the file, and if you use -3 it will be a fast, no check copy. Then I'd loop a checksum of the file on server A after the copy and compare that to the checksum from server B. If they match, you're done, close the loop; if not run the copy again and the checksum. If you just use the SCP with default options, the file will be cached on Server C, then copied to server A. This prevents problems in transit, and allows for other network traffic. If you want to mimic this, but perhaps a little faster, you can alter the first example with the -3 flag, and instead copy the file to server C, then copy the file to server A, checking the file at server A with a checksum comparison to the file on server B (you can repeat the copy if necessary). This is a similar operation, but allows you to delete the file from server C at the end, so that there's no cacheing overhead waiting to be freed up. I don't like playing with freeing up cached resources, especially in an active production environment. One mistake makes a big mess. I like a simpler option where the file is accessible directly so I can delete it from my own script. I'm also less practiced in some of the more advanced controls. I hope this helps.

Htd Tech

Posted 2016-07-19T17:27:28.360

Reputation: 9