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?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
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 firstname.lastname@example.org:/etc/var/test/test.txt
You can refer the following blog post for more information on pscp setup.
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 email@example.com:/opt/
If you need a key to login into the server, enter the following;
scp key.pem file.txt firstname.lastname@example.org:/opt
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
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.
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 email@example.com:~/
You can puth the full path or location in the path where the file is located.
~/ means the home directory of the user
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:
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/* user@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.
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.
OpenSSH is available for PowerShell since 2019. Instructions for installation are available from Microsoft's Docs site. Instructions for use of OpenSSH utilities are available on OpenSSH project site.
Basically, once you install the OpenSSH suite, scp will work as you are accustomed.
scp user@source:path/to/source/file user@destination:path/to/target/file
where source and destination are hostnames or IP addresses and a path and filename without a host name/address will be treated as local.