How to download a file from my server using SSH (using PuTTY on Windows) - windows

When I try downloading a file from my server onto my computer, it actually downloads the file onto the server.
(Note I am already SSH'd into my server before typing this command. I've watched tutorials on YouTube and people are using their terminal without SSHing into any particular server, however I don't think I can do this with PuTTY on Windows?)
scp -r -P2222 kwazy#mywebsite.example:/home2/kwazy/www/utrecht-connected.nl ~/Desktop/
The problem is that I am specifying the location to download the file as only ~/Desktop/
This creates a folder called Desktop in my server, instead of copying the files onto my local desktop.
I am able to use this command on Linux.
I have successfully download the folder onto my desktop:
I still need insight onto how I can do this on a Windows machine.

There's no way to initiate a file transfer back to/from local Windows from a SSH session opened in PuTTY window.
Though PuTTY supports connection-sharing.
While you still need to run a compatible file transfer client (pscp or psftp), no new login is required, it automatically (if enabled) makes use of an existing PuTTY session.
To enable the sharing see:
Sharing an SSH connection between PuTTY tools.
Even without connection-sharing, you can still use the psftp or pscp from Windows command line.
See How to use PSCP to copy file from Unix machine to Windows machine ...?
Note that the scp is OpenSSH program. It's primarily *nix program, but you can run it via Windows Subsystem for Linux or get a Windows build from Win32-OpenSSH (it is already built-in in the recent versions of Windows 10 and in Windows 11).
If you really want to download the files to a local desktop, you have to specify a target path as %USERPROFILE%\Desktop (what typically resolves to a path like C:\Users\username\Desktop).
Alternative way is to use WinSCP, a GUI SFTP/SCP client. While you browse the remote site, you can anytime open SSH terminal to the same site using Open in PuTTY command.
See Opening Session in PuTTY.
With an additional setup, you can even make PuTTY automatically navigate to the same directory you are browsing with WinSCP.
See Opening PuTTY in the same directory.
(I'm the author of WinSCP)

try this scp -r -P2222 kwazy#mywebsite.example:/home2/kwazy/www/utrecht-connected.nl /Desktop
Another easier option if you're going to be pulling files left and right is to just use an SFTP client like WinSCP. Then you're not typing out 100 characters every time you want to pull something, just drag and drop.
Just noticed /Desktop probably isn't where you're looking to download the file to. Should be something like C:\Users\you\Desktop

OpenSSH has been added to Windows as of autumn 2018, and is included in Windows 10 and Windows Server 2019.
So you can use it in command prompt or power shell like bellow.
C:\Users\Parsa>scp parsa#192.168.100.11:/etc/cassandra/cassandra.yaml F:\Temporary
parsa#192.168.100.11's password:
cassandra.yaml 100% 66KB 71.3KB/s 00:00
C:\Users\Parsa>
(I know this question is pretty old now but this can be helpful for newcomers to this question)

if you install git with git bash, you get SCP available on windows.

You can use WinSCP : https://winscp.net/eng/download.php
Or MobaXterm : https://mobaxterm.mobatek.net/download.html
It feels like FTP client. Also I don't remember setting up anything on my machine for this. It just fresh install and install SSH server (IDK if it matters though).
For MobaXterm :

If your server have a http service you can compress your directory and download the compressed file.
Compress:
tar -zcvf archive-name.tar.gz -C directory-name .
Download throught your browser:
http://the-server-ip/archive-name.tar.gz
If you don't have direct access to the server ip, do a ssh tunnel throught putty, and forward the 80 port in some local port, and you can download the file.

You can use the WinSPC program. Its access to any server is pretty easy. The program gives its guide too. I hope it's helpfull.

If you need something with GUI you can use FileZilla. it support SFTP.
It's perfectly working with ssh and you can even edit files and it will automatically upload the changes.

Related

how to install OpenSSH Server windows 11 OFFINE, without internet connection with powershell

I need to isntall SSH server on windows 11 using powershell. It should be a script that isntalls SSH server and logs you in and does everything untill this: ssh domain\username#servername
These are some methods I tried but unsuccessfully: (offline ofc)
https://it-infra-ya.com/en/ws19-sshserver_en/#toc2
from github, with .msi file (this works but I need to strat the script from server offline and this method doesnt work for me..)
I tried to do that by downloading file "OpenSSH-Client-Package_31bf3856ad364e35_amd64__" from https://www.exefiles.com/en/cab/openssh-client-package-31bf3856ad364e35-amd64-cab/ and using this command : PS C:\Windows\system32> DISM /Online /Add-Package /PackagePath:C:\Users\krivosik\Desktop\Scripts\scripts\OpenSSH-Client-Package_31bf3856ad364e35_amd64__.cab
I read that the "Online" part doesnt really mean online so it should work but it does not work for me..
I dont have that ISO file where the .cab file should be located so i cant really work with this: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/features-on-demand-v2--capabilities?view=windows-11.
Can anyone help how to do it the way i need to? thanks.
The best way would be to work with that .cab file but ill take anything :D

Is it possible to restart the server using WinSCP?

I transferred the files from my local computer to the remote directory using WinSCP, but I'm curious if I can restart/reboot the server using the same application or i need to do that using PuTTY.
I don’t think you can. WinSCP is a SFTP client, SFTP its a subsystem of SSH, but that does not mean that you can achieve everything you can do with SSH.
Here’s a complete list of commands supported by the SFTP protocol -> https://www.ssh.com/ssh/sftp/#sec-SFTP-Protocol
As you can see there’s no such ‘reboot’ instruction nor anything similar.
EDIT
As other answer says, WinSCP has the ability to issue remote commands https://winscp.net/eng/docs/remote_command
So you can do Commands > Open Terminal and issue a reboot
WinSCP has Console window, where you can execute most shell commands. The only limitation is that the command must not require terminal emulation. What command like reboot typically do not.
Short answer: you need putty to do it.
Long answer: If you know what you are doing you could have a watch of some kind and reboot the server if you copy a special file (via WinSCP) to the server, I would strongly advise against this.
If you use putty to do this you should be aware that the system user root is most likely forbidden to log in via ssh directly. So you have to use putty with some other user and use su/sudo to reboot.
To reboot a linux server
putty
sudo reboot

Run batch scripts on a remote server (windows) from jenkins

I've got a continuous integration server (Jenkins ) which builds my code (checks for compilation errors) and runs tests and then deploys the files to a remote server (not a war file, but the actual file structure) I do this with a Jenkins plugin which allows me to transfer files via samba, it does this nightly.
Now, what I need to do is run an ant command on the remote server. And after that I need to start the application server on the remote server, the application server is started by running a .bat file from the command line.
I'm pretty clueless how to accomplish this, I know Jenkins is capable of running batch commands, but how do I make them run in the context of the server and not the context of the build server?
If Jenkins on Windows, remote on *nix, use plink.exe (which is essentially command line PuTTy)
If Jenkins on Windows, remote on Window, use psexec.exe
If Jenkins on *nix, remote on *nix, use ssh
If Jenkins on *nix, remote on Windows, (update 2015-01) Ansible http://docs.ansible.com/intro_windows.html has support for calling Windows commands, eg powershell, from a unix/linux machine, https://github.com/ansible/ansible-examples/blob/master/windows/run-powershell.yml
Tell me what OSes are involved (both on Jenkins and remote), and I will flash this out further.
Edit:
The download page for psexec.exe lists all command line options. You will want something along the lines of:
psexec \\remotecomputername -u remoteusername -p remotepassword cmd /c <your commands here>
Replace <your commands here> with actual commands as you would execute them from command prompt.
Note that psexec first needs to install a service, and required elevated command prompt/admin remote credentials to do so.
Also, you need to run psexec -accepteula once to accept the EULA prompt.
Following Slav's answer above, here is a simpler solution for Jenkins (*nix) to remote (windows):
Install an SSH server on your remote windows (MobaSSH home edition worked well for me)
Make sure your Jenkins user, on your Jenkins machine, has the required certification to open an SSH connection with your remote (you can simply open a terminal and ssh to your remote once, then accept the certification. Make sure it is saved for the Jenkins user).
You can now add an execute shell build phase in your Jenkins job which can SSH to your remote windows machine.
Notes :
The established connection might require some additional work - you might have to set windows environment variables or map network drivers in order for your executed commands or batch files to work properly on your windows machines.
If you wish to run GUI related operations this solution might not be relevant (Following my work on running automation tests which require GUI manipulation).
Using Jenkins SSH plugin is an issue, as seen here.
1、i install (MobaSSH home ) on my remote windows server .
2、and install jenkins ssh plugin
3、edit shell eg: go build project
4、it seems something wrong ,
" go: creating work dir: CreateFile C:\WINDOWS\system32\bsh\tmp: The system cannot find the path specified."
I ended up going with a different approach after trying out psexec.exe for a while.
Psexec.exe and copying files over the network was a bit slow and unstable, especially since the domain I work on has a policy of changing password every months (which broke the build).
In the end I went with the master/slave approach, which is faster and more stable. Since I don't have to use psexec.exe and don't have to copy files over the network.

Confusion about FTP

I am learning web development and I'm a bit stuck with FTP. I know it's used for file transfer but how do I actually use it? I found some PHP functions to connect to the FTP server and log in but what do I log in with? How do I create a username? Is FTP something like MySQL with it's own command line? Or is it something like Apache?
I am using Ubuntu 12.04 and I have LAMP installed. I found somewhere that I need to install a program to use FTP but I found somewhere else that I need to install FTP while installing PHP. This is really confusing.
Thanks.
FTP is File Transfer Protocol. It is not a programming language. FTP is used to connect to a computer to access its file system - to upload or download files. Imagine opening a folder on firends pc from you computer. In most linux you can type in a ftp address to the location bar in whatever file browser your using and access the ftp server as if it was a local folder. You can also use specific software for that - gftp, filezilla.
A ftp daemon does not come with lamp. Please refer to https://help.ubuntu.com/12.04/serverguide/ftp-server.html for details on how to install/configure a ftp daemon on ubuntu.
What you will use ftp for is to put your .php files on a remote machine. If you are doing things on your computer only it is likely that you do not need ftp.

How do you edit files over SSH?

I program with eclipse and sometimes use GUI text editors like SciTE or vim. However, I'm at a point in a project that requires me to edit files over a ssh connection in a 80 column SSH window.
Since I have to (* shiver*) sudo vim before I can open the file I'm not sure how to open the file in an editor outside the terminal (that would allow me to see the text wider than 80 columns). If the command line was larger then I guess using straight vim wouldn't be a problem.
I'm at a loss of how to deal with this situation and how I could turn this nightmare into a manageable coding environment.
Maybe you should simply mount the remote filesystem to your local machine and then use whatever editor you like. If running a Debian derivative, install sshfs
sudo apt-get install sshfs
and then mount the remote filesystem ( issue on your local machine )
mkdir ~/remote_code
sshfs $USER#remote.example.com:/home/$USER/code ~/remote_code
Once this is done you can access the code in ~/remote_code w/ any of your GUI tools and without the bandwidth overhead of using ssh -X (however you still need a good connection w/ a low ping time).
PS: When using ssh I can make the terminal as wide as it fits my screen and then use its full width, so I fear I don't completely understand your issue.
WinSCP is a SSH client ftp-like. The default editor is primitive but can be change.
There are various options.
You can make the terminal larger. ;)
If you have a graphical environment installed on the machine you are ssh'ing into, you can login with ssh -X (or xdeep-putty if you are on Windows) to enable window forwarding. You can then run your favourite editor on the remote machine, whose graphical output is forwarded.
Finally, you can mount the ssh connection into your file system, using for example fuse (similar options might exist for non-linux operating systems). That allows you to access any file on the remote machine as if it were in your filesystem, with your favourite editor, locally.
I'm not 100% sure if this works for files owned by root, but if your desktop is KDE & your remote system is Linux (or pretty much any form of *nix), you can get konqueror to access the remote machine using the "fish://" protocol. From there you can open the file from konqueror using kate, or your preferred editor, and konqueror will take care of copying the file to your local machine and copying it back when you save.
Failing which the X11 forward is a good option, but X11 over ssh to remote sites can be slow. "ssh -X -C" compresses the data stream and can give better performance.
Notepad ++ has a plugin for editing files remotely over ssh. I've used it before, but I definitely prefer Kate on KDE using the fish protocol.
http://www.inmotionhosting.com/support/website/ftp-client-setup/connect-ftp-notepad-plus
Forward your X11 session to your terminal.
http://dragonwall.net/xdeep-putty.html
This probably belongs on superuser.com.
You might try the Komodo editor. It has a feature to load a 'remote file' over ssh. It's really convenient.
Emacs and ange-ftp.
If you're on Ubuntu, go to Nautilus (file explorer), connect to server (adding sftp:// to the hostname), then voila! You can easily launch gedit to edit your files now.
On Windows, you can use MobaXterm ( http://mobaxterm.mobatek.net ): it has a built-in SSH client with a very useful "SFTP browser".
As soon as you connect to your remote server using SSH, you will see your remote files displayed in this graphical SFTP browser. Just double-click on your files and you will be able to edit them directly on your remote server through SFTP.
I use Cyberduck and Sublime Text 2
FileZilla did the trick for me. Notepad++ can be used with it which is awesome.
If you using windows, try Editplus. It's not free but allows you to open files directly over scp. Custom syntax files are coming really handy, too.
Recent versions of ultraedit do exactly what the OP is asking for elegantly (IDM software, v10 and up support SSH iirc). I do most of my coding remotely like that, been using it for years, works great with no intermediate files etc. Obviously it also does FTP etc too if you're so inclined.
I actually found this page whilst looking for a linux equivalent of ultraedit..
If you are more GUI-oriented and use one of the more newbie-friendly Linux distros like Ubuntu or Mint, this is another option and does not require any more installations.
You should have nemo as your default file manager. It may not be called "Nemo" on the menu, so go under Help > About of your file manager ("Files" app) to see.
In nemo, go to File > Connect to server, enter your remote machine's details (SSH's default port is 22), and then open the files just like any file on your local machine, with whatever editor you prefer. You can even close Nemo and continue working in your editor.
From the address bar, it seems to be using the sftp protcol.
Just be aware that if your remote host has an inactivity timeout for the SSH connection, this will also prevent you from saving changes in the editor after the timeout has dropped the connection...
Since sshfs is not supported in WSL at the moment, the tool that worked for me is sshfs-win.
Installation Steps
Go here and click "download winfsp"
Install it
Go here and download the installer
Install it
Open windows explorer and right-click "This PC" > "Map Network Drive..."
Select a drive letter (B:), type in "\\sshfs\debian#10.13.100.36" and click Finish
Boom, done. Now you can have a B: drive on your computer and just do whatever with those files. Open them with VSCode, delete them, whatever you like
If you work in IntelliJ IDEA, you can use Friendly Terminal plugin instead of the native terminal. It allows to open and edit remote files in IntelliJ IDEA editor. Video

Resources