How to get a file from my path d:/test.txt and copy it to /etc/var/test/test.txt

I've tried this:

scp d:/test.txt /etc/var/test/test.txt

but that didn't worked, how to set the hard disk from where I copy my files?

  • Looks like the slash after d: is the wrong way round? – Paul Mar 1 '16 at 14:47

10 Answers 10


Umm, if you're using cygwin you want that command to look like

scp /cygdrive/d/test.txt <linux ip>:/etc/var/test/test.txt

Or you can use WinSCP, you'll probably find that simpler.

| improve this answer | |

The best way to copy files from Windows to Linux using the command line is through pscp. It is very easy and secure. For pscp to work on your windows machine, you need it add its executable to your systems path. Once it is done, you can use the following format to copy the file.

pscp -pw password D:\test.txt user@

You can refer the following blog post for more information on pscp setup.


| improve this answer | |
  • To improve your answer, I suggest you include some relevant quotes / summary in your answer ... (leaving the hyperlink in it is fie, eg for those who want more background info, etc) – Pierre.Vriens Feb 25 '16 at 11:16
  • is it possible to tar a directory on linux and send it to windows using pscp? – amandanovaes Jun 4 '19 at 2:17

Assuming you are on Windows, best way is to download and install cygwin. Get the path to the binary folder and add it to the system path. You can now run Linux commands on your command line.

Open the command prompt and go to the directory where your file is that you want to copy. Run the following command;

scp file.txt root@
  • scp - secure copy command
  • file.txt - file you want to copy
  • root - username used to log onto CentOS machine
  • - IP address of CentOS machine. Needless to say your Windows machine and the CentOS machine have to be able to communicate with one another
  • :/opt - This is the directory with which you save the file to, I generally save everything to the /opt directory
  • Don't forget the @ between the username and IP Address and the : between the IP Address and directory you are saving the file to

If you need a key to login into the server, enter the following;

scp key.pem file.txt root@

For handiness sake I just copy the file I want to copy across to the key file directory, that way you know everything will run smoothly

| improve this answer | |

I would highly recommend to use WinSCP if you're a Windows user. It has a good intuitive interface and gets the job done easily and with no pain.

Download link

enter image description here

| improve this answer | |

First you have to install any ssh client (OpenSSH) which support command line interface for your windows machine:

And add its path to windows Variable:

My Windows System output like below:

enter image description here

Then you will able to execute the same commands on your windows machine

You can copy also complete directory by executing:

scp -r path/to/dir_name/* root@remote-ip:/path/to/destination_dir

To Copy Single File:

scp -r path/to/file_name.zip user@remote-ip:/path/to/destination_dir/

Replace the file extension with your own file.

| improve this answer | |

If you are on the remote machine:

scp user@hostname:D:\text.txt user@hostname:/etc/var/test/test.txt

If you are currently on Windows machine:

winscp D:\text.txt user@hostname:/etc/var/test/test.txt
| improve this answer | |

to copy a file from windows to linux write:

scp -i privatekey pathFileOnWindows user@publicIp:pathDirectoryLinux 

(the colon : is important!)


//I am located here in my console


//I'm executing the next command

scp -i C:\Users\oscar\Documents\llaves\ubuntu.pem C:\Users\oscar\Documents\index.html ubuntu@ec2-54-94-247-176.sa-east-1.compute.amazonaws.com:~/

You can puth the full path or location in the path where the file is located. ~/ means the home directory of the user ubuntu

| improve this answer | |
  • In 2020 PowerShell now has scp available without having to install anything else – Daniel Feb 27 at 21:55

WinSCP is definitely an useful utility, especially if you want a graphic interface. But if you're looking for a command line alternative without having to deal with installing cygwin, there's also pscp which is part of the PuTTY collection of tools.


| improve this answer | |

if you are using windows and want to copy to the linux server then install the WINSCP and just use the drag and drop

| improve this answer | |

pscp with -pw exposes my password, which I don't like. The below answer works just like me using scp on linux -> linux.

pscp -scp C:\Windows\foo.txt username@
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.