views:

111

answers:

2

I am trying to make ssh connection via putty through Java to a remote server. I was able to do it from double clicking the putty.exe and doing ssh.

How do I be able to do it from command prompt. I get invalid port number message. But it works via putty.exe(GUI)

I am using :

c:> putty.exe -ssh -l username -pw password -m someCommandtoExecute remote_host(_name or IP)

Thnaks in advance.

A: 

I don't have any trouble getting a connection using

C:\Program Files\PuTTY> putty -ssh -l <username> <hostname or host ip>

The only things that leap to mind are either 1) a problem with the script used as part of the -m argument, or 2) an incorrect use of capitals. Could the error message be generated by the script rather than the command? Could you possibly have used

C:\Program Files\PuTTY> putty -ssh -L <username> <hostname or host ip>

A capital L is for a port-forwarding setup, while lowercase l is for specifying a login (username).

A couple of notes:

plink does a similar job without opening a new window. Might be worth exploring, but the commands are pretty much identical.

It's generally not a good idea to put plaintext passwords on the command line. You would be better off exploring keys, especially if this is for an automated process. A quick search will turn up a variety of links, but you'll need to check for the best way to handle your particular situation. If you want this to operate as part of an automated script, you'll do different things than if you want to run it as part of an interactive session where you already have Pageant running.

If you do go with keys, then your command line becomes

putty -ssh <username>@<host> -m <script on local machine>
tmsilver
Even when I do: putty.exe -ssh -l usrnme -pw pswd gives the same error
Sorry for the delay in responding ...
tmsilver
+1  A: 

I did some testing tonight on a Windows computer connecting to a BSD server. If I enter

putty.exe -l username -pw password server.domain.com

I get connected without a problem. If I try

putty.exe -l username -P password server.domain.com

I get an alert box opening with a title of PuTTY Internal Error and a message of Invalid Port Number. In fact, that's the only time I can get that error message.

If you are using a good password (mixed case, special symbols, etc) the password may be the source of the problem. Maybe try enclosing the password in double quotes, as in

putty.exe -l username -pw "password" server.domain.com

Are you using the latest version of PuTTY? I'm using 0.60, which appears to be the most recent version.

Finally, and I know these sound really simple, are you manually entering this on a command prompt while you are testing, or is your testing being done as part of a larger script? For simplicity's sake, I would get it working manually before trying to integrate it into a larger process. For the same reason, I would also leave off trying to automatically run the remote command (-m ) while trying to figure out this issue. It looks like you already are, but it never hurts to check ...

If you can't tell, I'm kind of grasping at straws here. I can't seem to replicate the problem except when there is a -P included somewhere on the command line.

tmsilver