user10996603
user10996603

Reputation:

Putty: Network error : cannot assign requested address

Hello I have written a macro to ssh to a server whose username and password are stored at A1 and B1 respectively. When the the macro gets invoked , putty throws error Network error : cannot assign requested address

Sub putty()
    Dim un As String, pwd As String, pcmd As String, pline As String
    Dim shellObj As Object, runCmd As Object, sOut As Object  

    un = Range("A1").Value
    pwd = Range("B1").Value
    Set shellObj = CreateObject("WScript.Shell")
    pcmd = "C:\Program Files\PuTTY\putty.exe " & un & "@15.xx.xx.xx -pw " & 
    pwd & " who"
    Set runCmd = shellObj.exec(pcmd)
    Set sOut = runCmd.StdOut

    While Not sOut.AtEndOfStream
        pline = sOut.ReadLine
        Debug.Print pline
    Wend
End Sub

Is there any workaround for this.

Upvotes: 2

Views: 11906

Answers (2)

Phil Brown
Phil Brown

Reputation: 411

One option is to specify the port directly with -P <port> (e.g., -P 22), per the docs: https://the.earth.li/~sgtatham/putty/0.74/htmldoc/Chapter5.html#pscp-usage

It seems that the PuTTY UI displays the Port value as 22 by default, even if there is no "Default Settings" session stored in the registry, so it appears to be valid even though it is not. The fix for this is to launch PuTTY, select the "Default Settings" and then click Load/Save.

EDIT: This is a known bug in PuTTY 0.74 (https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/pscp-port-0.html).

Upvotes: 1

Nekudotayim
Nekudotayim

Reputation: 181

Make sure the default port is set correctly. If you open putty, the port field in "default settings" may not be empty

Upvotes: 0

Related Questions