Copying files from local clients to remote servers is a task required of all types of analysts. Certain graphical tools, such as WinSCP, can aid those who prefer graphical utilities to command line equivalents. But often times, the command line solution is quicker, more elegant, and has the advantage that any collection of commands can be placed in a shell script and run on-demand.
In this brief post, we’ll demonstrate how to copy files from a local Windows client to a remote Linux server. It is assumed that Cygwin is installed on the Windows client, and that it is possible to connect to the remote Linux server from the terminal via ssh.
The command line specification for scp is:
$ scp [-P <port>] <local_file> <remote_username>@<remote_hostname>:<remote_directory_location>
Lets assume we’ll be connecting as
remote.11.com using ssh via port
3337, and we want to the local file
results.zip to the remote file system location
/home/uid414. The corresponding scp command would be:
$ scp -P 3337 results.zip firstname.lastname@example.org:/home/uid414
One thing to note: If your current working directory isn’t where
results.zip is saved, be sure to include the
/cygdrive prefix when specifying the path to the file. For example, if
results.zip is located in
U:/Archive, and your current working directory is some other location, from Cygwin the command should be:
$ scp -P 3337 /cygdrive/u/Archive/results.zip email@example.com:/home/uid414
Also, if any directory names in filepath have spaces, surround the filename in double quotes. If
results.zip is instead saved to
the corresponding scp command would be:
$ scp -P 3337 "/cygdrive/u/Local Archive/results.zip" firstname.lastname@example.org:/home/uid414
Note that going the other way, copying files from a remote host to the localhost, is only possible if an ssh server is installed on the local client, and Windows does not come with an in-built ssh server.