I'm SSHing into a Linux machine using PuTTY and trying to copy a file down somewhere (anywhere) to my local machine. I figure SCP is the best candidate for the job but don't really care, so long as the solution works!
FTP is very popular protocol to transfer files over network and internet. FTP is very popular protocol to transfer files over network and internet.
I cd
to the directory containing the file I want (app.war
) and type the following:
I've tried both to no avail:
It got me thinking that perhaps SCP is a client/server tool and requires a client on my Windows machine, which isn't there.
Am I just using the wrong syntax? Or am I way off-base? If so, what options do I have? Thanks in advance!
Martin Prikryl5 Answers
in order for you to copy files back to your Windows you need SSH daemon/service to be running on your Windows, it's much easier to use this tool instead, it has an ability to import sessions from Putty, very plain forward client you'll love it!
alexusalexusYou are correct. SSHD is the SSH server services that runs on the host. It accepts connections from SSH clients (like PuTTy), SCP clients, and SFTP clients.
You can download pscp
from the same website where PuTTY is hosted.
From the windows machine, you would execute a command similar to
pscp.exe someuser@somehost.com:/path/to/app.war c:tmp
To SCP a file to a Windows machine, you need an SSH/SCP server on the Windows.
There's no SSH/SCP support in Windows by default. You can install Microsoft build of OpenSSH for Windows (Releases and Downloads). It's available as optional feature on Windows 10 version 1803 and newer. It can also be manually installed on older versions of Windows.
I have prepared a guide for setting up SSH/SFTP server on Windows using this Microsoft build of OpenSSH.
See also Is IIS SFTP natively supported by Windows?
Though as you SSH into the Linux server from the Windows machine, you actually can download a file from the Linux server to the Windows server, instead of trying to upload the file from the Linux server to Windows server.
In you have an SSH access from Windows to Linux, you have an SCP access too (or even better an SFTP access).
Use any SCP/SFTP client available.
You can use WinSCP SFTP/SCP client, which has both GUI and command-line interface.
Another alternative is PuTTY toolset, which includes the pscp
command-line tool with a syntax similar to the OpenSSH scp
command.
(I'm the author of WinSCP)
Martin PrikrylMartin PrikrylWindows 10 now has OpenSSH built in.https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
Get an admin command prompt
Check available versions
Install client
Install server
Start server and enable at boot
Find your Windows IP address
On your remote (Linux) machine, find your IP address.
Create a public SSH key
Copy public key from local (Windows) to remote (Linux) machine so you don't have to type in a password all the time.
Note that ssh-copy-id is not currently available on Windows.
Do the same on your Linux machine (Note, ssh-copy-id does not work)
The method above did not work for me, so I ended up manually SCPing the public key over and pasting it into the C:/Users/YOU/.ssh/authorized_keys file.
That still did not work, so I had to modify the sshd_config file.
Open Notepad as Administrator
Open %programdata%sshsshd_config
Add the following lines:
- Reboot
Create a password on Windows if you don't already have one
-- Note, you can still disable the Windows login screen by a) Setting the 'Require sign-in' option to never and b) Using the 'netplwiz' command and unticking the 'Users must enter password...' checkbox.
Now you should be able to SSH or SCP from your Linux machine
Step 1: Download pscp
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
(Based on your machine download the respective version)
Step 2: Get familiar with the pscp commands
To do so, open command prompt in your windows machine, go to directory where you have downloaded pscp.exe and type 'pscp'
Step 3: Transfer file from your Linux machine to Windows machine
open your command prompt, and run below command providing your details:
pscp usernameofyourlinuxmachine@10.40.000.000:/path/of/your/File/nameofyourfile.txt ./
and this command will transfer the file from your Linux machine to the current directory of your windows machine
Step 4: Transfer file from your Windows machine to Linux machine
open your command prompt, and run below command providing your details:
pscp nameofyourfile.txt usernameofyourlinuxmachine@10.40.000.000:/path/where/youwantyourfile
I hope this is clear and works for you all!
Not the answer you're looking for? Browse other questions tagged linuxwindowsftpputtyscp or ask your own question.
I am using the following command to transfer from a SFTP location to a local folder. This transfers all the files from the SFTP location to the local folder.
How do I transfer files that are only for e.g. older than yesterday?
Thanks.
Martin PrikrylFtp 1 Pscp Exeter Ca
1 Answer
The pscp
cannot do that.
All you can do, is to the list all the files using the -ls
switch, parse the output to find the old files and generate a download script for the identified files.
Or use an SCP/SFTP client capable of selecting files by their timestamp.
For example with WinSCP SFTP/SCP client, you can use the following batch file (.bat
) to download the files older than one day:
References:
- Guide to automating file transfers from SFTP/SCP server
Ftp 1 Pscp Exeter Ny
(I'm the author of WinSCP)