copy a file with scp, which is not stored on a filesystem

Posted on

Problem :

I need to copy a .war file, which i currently just can reach over the UI with “http://server:host/directory/my_file.war“. So its not stored on a fileserver. Im logged on a server A and the file needs to be saved on server B.

Is it in general possible to download files from a server A, that are not stored on a fileserver with the scp command to a server B?

Thanks in advance.

Solution :

No, scp does not support http:. First copy the file to your computer using curl or wget (or save it with your browser), and then use scp to copy from a local filesystem.

If you have shell access on server B, just ssh to server B, and run wget there to pull the file down directly. This is better in that it only uses bandwidth on serverB and the webserver (in case that matters to you) — see below for an alternative solution that uses much more bandwidth.

Or, if for some reason you can’t download the file directly to server B, do something like:

serverA$ wget --output-document=- http://server:host/directory/my_file.war | 
    ssh user@serverB "cat > /path/to/my_file.war"

This tells wget to fetch the URL to stdout, and then ssh will send that data to serverB and redirect it to a file. Unfortunately, scp can’t read a from stdin, so you will need shell access on serverB in order for this to work. Note that if you do this, you’ll use 2x bandwidth on serverA (to pull the file from the webserver, and then push it to server B), and you’ll use 1x bandwidth on the webserver and serverB.

Leave a Reply

Your email address will not be published. Required fields are marked *