Is it possible to restart the server using WinSCP? - putty

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

Related

Start Windows GUI program in the PuTTY shell

I created an SSH session into my localhost through PuTTY. I am running OpenBSD server on the localhost which is a Windows 7 machine. The login was successful. Now I want to start programs in the PuTTY shell for example notepad.exe. I changed the directory to c:\windows\system32. The command start notepad runs without error but I don't see any window.
Is the notepad running in the background without a windows. If yes, how to make the window visible??
Yes, it's quite likely the Notepad is run in an invisible Windows session on the server. Note that it does not make a difference in this case that the server is the local machine.
If you hoped for the window to appear on the "local" machine magically, you are out of luck.
Generally, it's possible to run a GUI application on remote machine and see the GUI locally. On Unix it's quite common. Typically X Window is used for that.
But Windows GUI applications cannot be "tunneled" via SSH session to a local machine.

How to download a file from my server using SSH (using PuTTY on 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.

Exec a program on client runs a programm on server

First of all I have spent over 4 hours researching this topic..
So I have a Windows 2008 r2 root server at the moment. I connect to it via Remote Desktop.
Now I want to write a program that runs batch files on the server but the program is at client side, I have tried to setup an SSH server on my Windows server with Freesshd.
That seems to work but the programs are not shown. (In Taskmanager are they)
Is there way (prefer SSH) to let them show normally?
The goal is to restart programs (Gameservers).
My Program will work so: if I press restart server it will connect (if SSH) via Putty to the server to exec the batch file.
Or will start another program with parameters something like this:
Clientprogramm -ip 95.25.115.** -user Administrator -p xxxxxx C:\gameserverdir\start.bat
Simple and fine. I have done that already for Linux and there it isn't that hard.
So if you have an idea that can help me would be nice to know.
Both system are Windows!
If you are using SSH, the tool you need is plink. It's putty for command line.
Or, as indicated in comments, you can use psexec, or powershell, or vbscript, or .... BUT started programs are only "visible" in the same session from where they were started.

Run script on remote machine via telnet (not SSH)

I need to somehow run a script which resides on a remote machine running Ubuntu.
SSH or any other connection type that requires complex encryption is not possible.
The client that will connect to the remote machine is only capable of opening a port and sending and receiving strings.
Can anyone tell me how to do this?
Why is your remote Ubuntu machine "not natively capable of SSH". That's nonsense.
But if you want a solution, use expect - it can run ftp/telnet or any other terminal-based application. It can react to different input, and type in a password.
There are python and perl-based packages that also do this.

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