Search code examples
matlabtelnetplink

How to telnet in MATLAB using Plink


I am trying to telnet using Plink through MATLAB. I have tried the following commands and failed:

command = 'C:\MyDirectory\plink.exe';
[status,cmdout] = system(command,'-echo')

cmdout returns the options and inputs available to Plink. But when I try the following it doesn't work:

edit I get an error when I try to run the following:

command = 'C:\MyDirectory\plink.exe -telnet @thisUser@someIP 22';
[status,cmdout] = system(command,'-echo')

What's the right way to do this?

edit 2 Here is the actual command and the result I get back:

>> command = 'C:\Program Files (x86)\PuTTY\plink.exe -telnet @192.168.14.20';
>> [status,cmdout] = system(command,'-echo')
'C:\Program' is not recognized as an internal or external command, 
operable program or batch file. 

status =

     1


cmdout =

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

A username is not required so I have not put one prior to the '@' symbol. But, as shown, i am still receiving the '... not recognized...' message. Not really sure why.


Solution

  • The correct syntax is:

    "C:\Program Files (x86)\PuTTY\plink.exe" -telnet thisUser@someIP -P 22
    
    • Double quotes around the path to plink.exe (to escape the spaces in the path)
    • No @ before username
    • Specify the port using the -P switch.

    Though the Telnet protocol uses the port 23. The port 22 is for the SSH. So either use the default Telnet port 23 (no need to specify it). Or you actually want to use the SSH (the -ssh switch, not the -telnet).