Forum Discussion

Philip_Baird's avatar
Philip_Baird
Community Expert
10 years ago

WinSCP COM automation fails

Hi, I have registered the WinSCP library as per the instructions on the WinSCP site:

 

Register WinSCP COM

 

I have tried executing the following code to simply open and close a connection:

 

 

function testWinSCP() {
  var session = Sys.OleObject("WinSCP.Session");
  var sessionOptions = Sys.OleObject("WinSCP.SessionOptions");
  sessionOptions.Protocol = session.Protocol_Sftp; // Not sure if correct
  sessionOptions.HostName = "10.23.0.41";
  sessionOptions.UserName = "oracle";
  sessionOptions.Password = "Orac1e";
  sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 25:e2:6e:db:39:9e:50:e0:6f:57:7f:54:07:0a:a2:a1";
  
  try {
    session.Open(sessionOptions);
  } catch( e ) {
    Log.Message( e.message );
  } finally {
    session.Dispose();
  }
};

but this fails with in an "Invalid procedure call or argument" Exception being thrown.

 

 

What else do I need to do to get this going? It doesn't help with the debugger not displaying any methods or properties of the objects.

 

I believe it is actually creating the objects as setting sessionOptions.SshHostKeyFingerprint to a string that does not match the pattern for ssh throws an Exception stating such.

 

Regards,

Phil Baird

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Phil,

    Try adding the WinSCPnet.dll assembly to the CLR Bridge and calling it via dotNET. Eliminating the COM interop layer should help avoid data conversion issues, or at least give you more meaningful errors:

     

    function testWinSCP() {
      var session = dotNET.WinSCP.Session.zctor();
      var sessionOptions = dotNET.WinSCP.SessionOptions.zctor();
      sessionOptions.Protocol = dotNET.WinSCP.Protocol.Sftp; // Not sure if correct
      sessionOptions.HostName = "10.23.0.41";
      sessionOptions.UserName = "oracle";
      sessionOptions.Password = "Orac1e";
      sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 25:e2:6e:db:39:9e:50:e0:6f:57:7f:54:07:0a:a2:a1";
    
      try {
        session.Open(sessionOptions);
      } catch( e ) {
        Log.Message(e.message);
      } finally {
        session.Dispose();
      }
    }

     

    • Philip_Baird's avatar
      Philip_Baird
      Community Expert

      Hi Helen, I am actually trying to find a way to avoid using the CLR Bridge which is why I was investigating the COM library.

       

      I have found that Test Complete appears to have problems resolving the dependencies for the WinSCPnet.dll assembly.

       

      This manifests itself by the WinSCP Namespace not being available under the dotNet Object

      with the only way to get it to work is to register the assembly iin the Global Assembly Cache which has caused issues when executing tests on different machines.

       

      I have started writing a static .Net Interface that abstracts the WinSCPnet.dll assembly which so far appears to be working ok.

       

      Phil