Putty is offline. need to automate the " pressing" of the the escape key to connect - putty

I am using a batch file to open Putty with a saved session called test, which is a serial connection.
putty.exe -load test
normal conditions: once the session is opened it is offline. It needs the escape key pressed to connect.
I would like to automate this step - the escape key being pressed. I have tried
putty.exe -load test ^, with ^ being the escape key.
Any advice would be really appreciated.

putty.exe -load test ^ won't load and connect any session ...
this works pretty simple (just successfully connected like that on Linux):
putty.exe -load "test"

Related

PuTTY PSFTP command line works as Admin, fails as User

I have an interesting dilemma with PuTTY PSFTP.
Set up...
Pageant .60
putty .60
Used command:
D:\psftp.exe -load myserver.domain.us.com -l User1 -b MyCommand Script
This loads PuTTY PSFTP, logs in using the user ID with the help of Pageant and then sends a file using commands in the script.
This works great while logged in as an Admin on the server.
It fails while logged in as a regular user on the server:
"psftp: no hostname specified;"blah blah blah.
Including -v reveals no further messages.
What possible delta could there be with permissions or other settings between a server Admin and regular user when it comes to PuTTY?
You load PuTTY stored site myserver.domain.us.com.
That is stored in Windows registry of the local account.
If you run the script using a different account, it won't see the site definition.
You have to define the session completely on command line. What you probably even attempted.
Remove the -load;
Add -ssh to make it clear you want to use SSH (but it's default anyway)
Add -hostkey=... with a fingerprint of the SSH host key (you need the latest version of PuTTY for the -hostkey switch, but you need to upgrade anyway, the version 0.60 is not secure).
D:\psftp.exe -ssh myserver.domain.us.com -hostkey=... -l User1 -b MyCommand Script

Open putty ssh connection over SOCKS5 proxy via command line

I tried to open putty ssh connection over SOCKS5 proxy via command line.
putty.exe -P port -pw password username#host -nc proxyhost:proxyport
This command doesn't work and I think it is incorrect. I tried a lot of variants of this command, but putty user manual doesn't contain necessary information.
I tried to connect to my host throw putty UI and it works fine.
For openSSH similar command looks
ssh -o "ProxyCommand=nc -x proxyhost:proxyport %h %p" -p port username#host
If I were you I would create a "Saved Session" with Putty and launch it via command line:
putty.exe -load session_name
It will be easier to create a "Saved Session" via the PuTTY interface than toying around with the command line. And it seems like you already have it working through the PuTTY interface.
Even though this is an old thread I would like to add my two cents, as I found it hard to gather all the information necessary to set up a working ssh connection over a SOCKS-5 proxy using putty command line and this thread showed up in my result list.
TL;DR
It is currently not possible (as of putty v0.74) to route ssh traffic over a SOCKS-5 proxy using putty or plink as the proxy-command on the command line. You have to use an alternative like ncat for windows, e.g.:
putty -p <targetport> -proxycmd "ncat.exe --proxy-type socks5 --proxy <proxyhost>:<proxyport> <targethost> <targetport>" <targethost>
Details
The putty GUI allows the configuration of an SOCKS-5 proxy, see putty documentation.
As correctly stated in the answer, by BlakBat this configuration can be called via command line using the -load argument.
The command line argument -proxycmd triggers the use of a so called 'local' proxy connection (see the putty documentation again):
> 3.8.3.24 -proxycmd: specify a **local** proxy command
The local proxy command is a command issued on the local machine, that will handle the proxy connection (see the documentation about proxy types). ncat is such a command and it is able to interact with a SOCKS-5 proxy.
Finally, it is tempting to use plink/putty as the proxy command to avoid the use of multiple tools.
Putty claims to provide an alternative to the netcat utility via the -nc argument, however the putty documentation states:
If you want your local proxy command to make a secondary SSH connection to a proxy host and then tunnel the primary connection over that, you might well want the -nc command-line option in Plink.
If you try to use the -nc argument to open a SOCKS-5 connection your SOCKS server log might show something like this:
sockd[1234]: info: block(1): tcp/accept ]: 1.2.3.4.4711 1.2.3.5.1080: error after reading 1 byte in 0 seconds: unknown SOCKS version 83 in client request
This is an indication that an attempt was made to open an SSH session to the SOCKS-5 server.
So, unfortunately, to my knowledge your only chance is to use putty along with a netcat-like tool to establish a proxied SSH connection using an SOCKS-5 proxy.
Simple,
putty -D 8080 <user_id>#<server_name> -pw <password>

putty psftp " and ; in password

I am trying to create a vbscript to connect to a FTP server using putty. The problem I am having is the password has a ; and " in it. I have tried putting the password in " and also using \ to escape the charters
e.g.
-pw 3this;IsMyPwd" is what i want to use
Tried
"3this;IsMyPwd""" -> putty does not connect to remote server
-pw 3this;IsMyPwd""" -> putty does not connect to remote server
3this\;IsMyPwd\" -> putty does not connect to remote server
3this;IsMyPwd\" -> putty does connect to remote server but asks for a password or just hangs
-pw 3this;IsMyPwd"" > putty does connect to remote server but asks for a password or just hangs
The answer is to not use putty. I used WinSCP. You do not have to install it on the server you can copy WinSCP.com and WinSCP.exe to a folder.
Create a file with the commands, note that %22 url encoding of "
example of Cmd.txt file
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect
open sftp://USERNAME:password%3%22#ftp.server.org
ls
cd to_folder
ls
close
exit
Run the command C:\winScp> winscp.com /script=Cmd.txt

Automate executing a command on MikroTik router via PuTTY

I am trying to remotely add a user to a MikroTik router via terminal. Firstly I am opening PuTTY and then I type the right command to add the user but I always take the same mistake:
"Unable to open connection to 1.1.1.1.1" (here is my real address)
"Network Error: Cannot assign requested address"
What should I do?
The command that I insert to cmd is:
putty -ssh username#1.1.1.1.1 22 -pw mypass '/ip hotspot user add limit-uptime=1h server=all name=user1 password=user1'
Thank you in advance
The error message is really confusing. PuTTY got obviously confused by your wrong command-line syntax:
You have to specify the port number using the -P switch. Though you do not need to specify the port number at all, if it is the standard 22.
You cannot specify the command on the command-line of PuTTY. You need to use the PLink for that.
Do not quote the command, unless the quotes are really part of the command.
IP address has 4 numeric components, not 5. But I assume it is just a typo, when you obfuscated your real IP address.
plink.exe -ssh username#1.2.3.4 -P 22 -pw mypass /ip hotspot user add limit-uptime=1h server=all name=user1 password=user1
References:
The PuTTY command line
Using the command-line connection tool Plink

How to convert Windows FTP script to WinSCP?

I need to use WinSCP in my legacy vb6 code. I always used my script like this:
open ftp.myserver.com
myusername
mypassword
passive on
cd myfolder\
ascii
put C:\temp\test.xml test.xml
close
quit
Similar script (with little change) always worked for sslftp, psftp, etc.
Now I need to create script to make this WinSCP work but it keeps throwing "host not found error". I'm not even trying the script. I'm trying it on the command window.
winscp> open ftp.myserver.com
Searching for host...
Network error: Connection timed out.
same ftp works on regular command line ftp:
ftp> open ftp.myserver.com
Connected to myserver.
220 Gene6 FTP Server v3.10.0
User (...): myuser
331 Password required for myuser
Password:
230 User manager logged in.
How do I run WinSCP? The documentation doesn't show any such example.
WinSCP defaults to the SFTP protocol on the port 22. If you want to use the FTP, you need to specify that explicitly.
Also username and password come in session URL as part of the open command, not on separate lines. The passive mode is specified using the -passive=on switch.
open ftp://myusername:mypassword#ftp.myserver.com -passive=on
The ascii mode is specified using the -transfer=ascii switch of the put command (though the separate ascii command is also understood for compatibility):
put -transfer=ascii C:\temp\test.xml test.xml
It's the exit, not the quit.
See the complete guide for converting Windows FTP script to WinSCP.
You should also read the guide to automating file transfers to FTP server.

Resources