How to execute remote command using PuTTY over Telnet

2

1

I was created a .bat file to run PuTTY and it successfully runs. The problem now is, the command line I was key in were not executed, any solution for this?

My .bat command is:

putty -telnet -P 15555 test-PC -m C:\Users\tslai\Desktop\commands.txt

I'm connecting using Telnet, and I have a specific port number, which is 15555, the server name's is test-PC. commands.txt is the arguments that I make.

In commands.txt: only have a arguments, and it was tested can work properly if running directly by using command prompt.

laits89

Posted 2015-05-14T09:07:08.080

Reputation: 21

Answers

4

The -m command-line switch of PuTTY works for the SSH only, not for the Telnet.

See PuTTY documentation (emphasis mine):

3.8.3.6 -m: read a remote command or script from a file

The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.

There's no way to execute a command on the server automatically with PuTTY over the Telnet protocol.


Though you might be able to use Plink (PuTTY command-line connection tool).

As with PuTTY, you cannot use the command parameter as that works with the SSH only.

But you might be able to use input redirection:

plink.exe -telnet -P 15555 test-PC < C:\Users\tslai\Desktop\commands.txt

Martin Prikryl

Posted 2015-05-14T09:07:08.080

Reputation: 13 764

You are welcome. Though on SuperUser we thank by accepting and/or upvoting the answer.

– Martin Prikryl – 2015-05-15T06:29:25.133

I were tries with plink.exe, but it won't run the arguments i pass thru. How about run Putty.exe and after that pass an arguments into putty command box via only single batch file, do you know how to do that? – laits89 – 2015-05-15T09:08:22.010

You can to that only by simulating mouse-clicks. And that's a very unreliable method. – Martin Prikryl – 2015-05-15T09:09:26.640

What does the Plink do when you run it with redirected input? – Martin Prikryl – 2015-05-15T09:10:15.163

only run Putty.exe, but the arguments was ignored(didn't executed). – laits89 – 2015-05-15T09:49:39.457

Plink does not run PuTTY. Did you replace the putty.exe with plink.exe in your command-line? – Martin Prikryl – 2015-05-15T09:51:21.060

When i launched the plink.bat, the machine i connected to was stopped working and force closed the application. – laits89 – 2015-06-03T09:52:06.260

What is plink.bat? – Martin Prikryl – 2015-06-03T10:01:08.733

sorry, plink.bat is only the bat name, the contain inside is

plink.exe -telnet -P 15555 test-PC < C:\Users\tslai\Desktop\commands.txt – laits89 – 2015-06-03T10:14:58.720

0

The Telnet Scripting Tool is a program that provides the capability to script telnet sessions. Perhaps it would be a viable alternative for you.

moonpoint

Posted 2015-05-14T09:07:08.080

Reputation: 4 432