scp from Linux to Windows [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I am running a putty client on a Windows machine to connect successfully to a Linux box. Now I want to be able to copy a file from the Linux machine under the path /home/ubuntu/myfile to C:/Users/Anshul/Desktop on my local computer. The user at the Windows machine is anshul. I am giving the following command on putty but it is not working:
scp /home/ubuntu/myfile ip_address_of_windows_machine:C:/Users/Anshul/Desktop
I think the path for the Windows machine is wrong. Please help as I have banged my head on a large number of forums but none seem to give correct path for Windows server. Don't suggest alternate options like WinScp

This one worked for me.
scp /home/ubuntu/myfile username#IP_of_windows_machine:/C:/Users/Anshul/Desktop

Download pscp from Putty download page, then use it from Windows Command Line CMD as follows:
pscp username_linux_machine#ip_of_linux_machine:/home/ubuntu/myfile.ext C:\Users\Name\Downloads
Copying starts once you enter the password for the Linux machine.

Try this, it really works.
$ scp username#from_host_ip:/home/ubuntu/myfile /cygdrive/c/Users/Anshul/Desktop
And for copying all files
$ scp -r username#from_host_ip:/home/ubuntu/ *. * /cygdrive/c/Users/Anshul/Desktop

Access from Windows by Git Bash console (also works for CMD and PowerShell):
scp user#ip:/dir1/dir2/file "D:\dir1\dir2"

You could use something like the following
scp -r linux_username#linux_address:path/to/file path/to/local/directory
This will copy file to the specified local directory on the system you are currently working on.
The -r flag tells scp to recursively copy if the remote file is a directory.

Windows doesn't support SSH/SCP/SFTP natively. Are you running an SSH server application on that Windows server? If so, one of the configuration options is probably where the root is, and you would specify paths relative to that root. In any case, check the documentation for the SSH server application you are running in Windows.
Alternatively, use smbclient to push the file to a Windows share.

For all, who has installed GiT completly with "Git Bash": You can just write:
scp login#ip_addres:/location/to/folders/file.tar .
(with space and DOT at the end to copy to current location). Than just add certificate (y), write password and that's all.

Your code isn't working because c:/ or d:/ is totally wrong for linux just use /mnt/c or/mnt/c
From your local windows10-ubuntu bash use this command:
for download:
(from your remote server folder to d:/ubuntu) :
scp username#ipaddress:/folder/file.txt /mnt/d/ubuntu
Then type your remote server password if there is need.
for upload:
(from d:/ubuntu to remote server ) :
scp /mnt/d/ubuntu/file.txt username#ipaddress:/folder/file.txt
Then type your remote server password if there is need.
note: I tested and it worked.

I had to use pscp like above Hesham's post once I downloaded and installed putty. I did it to Windows from Linux on Windows so I entered the following:
c:\ssl>pscp username#linuxserver:keenan/ssl/* .
This will copy everything in the keenan/ssl folder to the local folder (.) you performed this command from (c:\ssl). The keenan/ssl will specify the home folder of the username user, for example the full path would be /home/username/keenan/ssl. You can specify a different folder using a forward slash (/), such as
c:\ssl>pscp username#linuxserver:/home/username/keenan/ssl/* .
So you can specify any folder at the root of Linux using :/.

To send a file from windows to linux system
scp path-to-file user#ipaddress:/path-to-destination
Example:
scp C:/Users/adarsh/Desktop/Document.txt root#127.0.0.1:/tmp
keep in mind that there need to use forward slash(/) inplace of backward slash(\) in for the file in windows path else it will show an error
C:UsersadarshDesktopDocument.txt: No such file or directory
.
After executing scp command you will ask for password of root user in linux machine.
There you GO...
To send a file from linux to windows system
scp -r user#ipaddress:/path-to-file path-to-destination
Example:
scp -r root#127.0.0.1:/tmp/Document.txt C:/Users/adarsh/Desktop/
and provide your linux password.
only one you have to add in this command is -r.
Thanks.

Here is the solution to copy files from Linux to Windows using SCP without password by ssh:
Install sshpass in Linux machine to skip password prompt
Script
sshpass -p 'xxxxxxx' scp /home/user1/*.* testuser#x.x.x.x:/d/test/
Details:
sshpass -p 'password' scp /source_path/*.* windowsusername#windowsMachine_ip:/destination_drive/subfolder/

As #Hesham Eraqi suggested, it worked for me in this way (transfering from Ubuntu to Windows (I tried to add a comment in that answer but because of reputation, I couldn't)):
pscp -v -r -P 53670 user#xxx.xxx.xxx.xxx:/data/genetic_map/sample/P2_283/* \\Desktop-mojbd3n\d\cc_01-1940_data\
where:
-v: show verbose messages.
-r: copy directories recursively.
-P: connect to specified port.
53670: the port number to connect the Ubuntu server.
\\Desktop-mojbd3n\d\genetic_map_data\: I needed to transfer to an external HDD, thus I had to give permissions of sharing to this device.

Open bash window. Preferably git bash.
write
scp username#remote_ip:/directory_of_file/filename 'windows_location_you_want_to_store_the_file'
Example:
Suppose your username is jewel
your IP is 176.35.96.32
your remote file location is /usr/local/forme
your filename is logs.zip
and you want to store in your windows PC's D drive forme folder
then the command will be
scp jewel#176.35.96.32:/usr/local/forme/logs.zip 'D:/forme'
**Keep the local file directory inside single quote.

I know this is old but I was struggling with the same. I haven't found a way to change directories, but if you just want to work with the C drive, scp defaults to C. To scp from Ubuntu to Windows, I ended up having to use (notice the double back-slashes):
scp /local/file/path user#111.11.11.111:Users\\Anshul\\Desktop
Hope this helps someone.

Try this:
scp /home/ubuntu/myfile C:\users\Anshul\Desktop

If you want to copy paste files from Unix to Windows and Windows to Unix just use filezilla with port 22.

Related

Jenkins copy files between 2 Server

Is it possible to copy an .war file from one server to another server. I know there is the command scp but it doesn't support password & username. So there is like the command sshpass but I heard about some security problems with this command.
My question now: is there a way to pass an password trough the scp command without something like sshpass?

How to access Windows directories inside ubuntu bash

How to access a file, say test.c, from the Windows 10 Desktop on the Ubuntu Bash shell.
Answer to this question:
https://stackoverflow.com/questions/38921301/bash-and-ubuntu-subsystem-in-windows-10
I can't comment (less than 50 reputation), and I can't answer it (question was put on hold), and I can't directly message the OP. So I thought I'd share the answer here for maybe a more reputation user can forward to him. Thanks!
On terminal
cd /mnt/c/Users/
or cd /mnt/d or any other drive
Then you can just move the files to the linux home directory
mv /mnt/c/Users/path/to/file/ ~/
I believe the question asked was :"Where is new Linux subsystem and Bash are located in Windows 10?"
Through windows explorer this should get you there:
C:\Users\USERNAME\AppData\Local\Lxss\home\USERNAME
see this article for more info: http://www.howtogeek.com/261383/how-to-access-your-ubuntu-bash-files-in-windows-and-your-windows-system-drive-in-bash/

copy directory from another computer on Linux

On a computer with IP address like 10.11.12.123, I have a folder document. I want to copy that folder to my local folder /home/my-pc/doc/ using the shell.
I tried like this:
scp -r smb:10.11.12.123/other-pc/document /home/my-pc/doc/
but it's not working.
So you can use below command to copy your files.
scp -r <source> <destination>
(-r: Recursively copy entire directories)
eg:
scp -r user#10.11.12.123:/other-pc/document /home/my-pc/doc
To identify the location you can use the pwd command, eg:
kasun#kasunr:~/Downloads$ pwd
/home/kasun/Downloads
If you want to copy from B to A if you are logged into B: then
scp /source username#a:/destination
If you want to copy from B to A if you are logged into A: then
scp username#b:/source /destination
In addition to the comment, when you look at your host-to-host copy options on Linux today, rsync is by far, the most robust solution around. It is brought to you by the SAMBA team[1] and continues to enjoy active development. Most distributions include the rsync package by default. (if not, you should find an easily installable package for your distro or you can download it from rsync.samba.org ).
The basic use of rsync for host-to-host directory copy is:
$ rsync -uav srchost:/path/to/dir /path/to/dest
-uav simply recursively copies -ua only new or changed files preserving file & directory times and permissions while providing -v verbose output. You will be prompted for the username/password on 10.11.12.123 unless your have setup ssh-keys to allow public/private key authentication (see: ssh-keygen for key generation)
If you notice, the syntax is basically the same as that for scp with a slight difference in the options: (e.g. scp -rv srchost:/path/to/dir /path/to/dest). rsync will use ssh for secure transport by default, so you will want to insure sshd is running on your srchost (10.11.12.123 in your case). If you have name resolution working (or a simple entry in /etc/hosts for 10.11.12.123) you can use the hostname for the remote host instead of the remote IP. Regardless, you can always transfer the files you are interested in with:
$ rsync -uav 10.11.12.123:/other-pc/document /home/my-pc/doc/
Note: do NOT include a trailing / after document if you want to copy the directory itself. If you do include a trailing / after document (i.e. 10.11.12.123:/other-pc/document/) you are telling rsync to copy the contents, (i.e. the files and directories under) document to 10.11.12.123:/other-pc/ without also copying the document directory.
The reason rsync is far superior to other copy apps is it provides options to truly synchronize filesystems and directory trees both locally and between your local machine and remote host. Meaning, in your case, if you have used rsync to transfer files to /home/my-pc/doc/ and then make changes to the files or delete files on 10.11.12.123, you can simply call rsync again and have the changes/deletions reflected in /home/my-pc/doc/. (look at the several flavors of the --delete option for details in rsync --help or in man 1 rsync)
For these, and many more reasons, it is well worth the time to familiarize yourself with rsync. It is an invaluable tool in any Linux user's hip pocket. Hopefully this will solve your problem and get you started.
Footnotes
[1] the same folks that "Opened Windows to a Wider World" allowing seemless connection between windows/Linux hosts via the native windows server message block (smb) protocol. samba.org
If the two directories (document and /home/my-pc/doc/) you mentioned are on the same 10.11.12.123 machine.
then:
cp -ai document /home/my-pc/doc/
else:
scp -r document/ root#10.11.12.123:/home/my-pc/doc/

scp + Avoid copy if the same file name located on remote machine?

Is there any option to tell scp command - not copy file from current machine in case file exists on remote machine
For example
On my machine I have the file -
/etc/secret-pw.txt
On Remote machine I have also the file -
/etc/secret-pw.txt
So
scp /etc/secret-pw.txt $remote_machine:/etc
Will destroy the secret-pw.txt, and scp will not ask questions about: overwrite the target file
Is there any option to avoid copy if file exist on target machine by scp?
Update: I can't install rsync or any other program.
You should be using rsync instead of scp. It will give you what you need.
If you can't install rsync (as you mentioned in the comments) you need to run a script beforehand to check if file exists and run it with ssh.
SCP does not offer any option, unfortunately.
But you can resort standard tools, like this:
ssh $remote_machine -- cp --no-clobber /dev/stdin /etc/secret-pw.txt < /etc/secret-pw.txt
Note that with this trick you gain all the functionalities of cp.

Is this the correct syntax to scp a downloaded file into Ubuntu?

I downloaded the latest version of swig that I need to move to Ubuntu. I was hoping someone could help identify what part of my syntax is incorrect. I've tried a number of variations but I can't quite seem to get it write.
I've tried
scp swig-3.0.2 user_name#111.111.11.111: swig-3.0.2
swig-3.0.2 is a directory (not copied)
scp swig-3.0.2 drubio#192.168.56.101: /home/drubio/swig-3.0.2
No such file or directory
I've tried implementing directions that I've found on askubuntu.com reproduced here:
# copy a file from local machine to server1.com
user#local-machine# scp ./somefile.txt user1#server1.com:/home/user2
# copy a file from server1.com to server2.com
user#local-machine# ssh user1#server1.com
user1#server1# scp ./somefile.txt user2#server2.com:/home/user2
user#server1# logout
# copy a file from server2.com to server1.com
user#local-machine# ssh user2#server2.com
user2#server2# ls
somefile.txt otherfile.txt
user2#server2# scp ./otherfile.txt user1#server1.com:/home/user1
user2#server2# logout
# can't copy a file TO local-machine because it's not accessible from internet
All I'm trying to do is to copy the downloaded swig-3.03 located on my local machine's Desktop on to Ubuntu. I've checked on my local machine where I'm at and I've verified that I am in the Desktop directory. My username is correct and the path is right. I'm assuming that the mistake is the destination point. Am I wrong to assume this?
The correct syntax is:
scp swig-3.0.2 user_name#111.111.11.111:swig-3.0.2
scp swig-3.0.2 drubio#192.168.56.101:/home/drubio/swig-3.0.2
Without the spaces!
The usage is for copy local to remote:
scp /path/to/my_local_file user#host:/path/to/my_copy_file
or for copy remote to local:
scp user#host:/path/to/my_remote_file /path/to/my_copy_file

Resources