Author Topic: Need help with winSCP  (Read 823 times)


  • Full Member
  • ***
  • Posts: 156
Need help with winSCP
« on: September 01, 2017, 10:38:02 am »
I have some code:

assemblydir = 'C:\Program Files (x86)\WinSCP'
ObjectClrOption( 'appbase', assemblydir )
ObjectClrOption ( 'use', 'WinSCPnet, Version=, Culture=neutral' )

objSessionOptions = ObjectClrNew( 'WinSCP.SessionOptions' )
objProtocol = ObjectClrNew( 'WinSCP.Protocol' )
Sftp = ObjectClrType( 'WinSCP.Protocol', objProtocol.Sftp )

objSessionOptions.Protocol = Sftp 
objSessionOptions.HostName = ''
objSessionOptions.UserName = 'xxxxxx'
objSessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

objSession = ObjectClrNew("WinSCP.Session" )


objTransferOptions = ObjectClrNew( 'WinSCP.TransferOptions' )
objTransferMode = ObjectClrNew( 'WinSCP.TransferMode' )
objTransferOptions.TransferMode = ObjectClrType( 'WinSCP.TransferMode', objTransferMode.Binary )

and it is erroring out with a 1261 COM/CLR: Exception at objSession.Open(objSessionOptions)

Version appears to be right.

Code does run on a 32bit machine compiled, but does not on a 64 bit machine using same 32 bit exe.

Any ideas?


  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: Need help with winSCP
« Reply #1 on: September 01, 2017, 11:20:59 am »
Never have had any issues using WinSCP on 64-bit Windows and don't see how the same compiled script could execute on 32-bit Windows because 32-bit Windows doesn't normally have a "Program Files (x86)" folder.

At any rate, you should click the "More Error Info" button on the error message box, if it is enable -  it usually is for CLR errors.  The WinBatch CLR hosting subsystem should give you a good description of the problem as reported by the assembly.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


  • Full Member
  • ***
  • Posts: 156
Re: Need help with winSCP
« Reply #2 on: September 01, 2017, 11:23:39 am »
I had modifies that portion of the script that pointed to "Program Files (x86)", so I had two versions of the same compiled exe.

Other than that, same script

From the debug trace

[CLR Error]
mscorlib=Could not load file or assembly 'WinSCP, Version=, Culture=neutral' or one of its dependencies. The module was expected to contain an assembly manifest.


  • Full Member
  • ***
  • Posts: 156
Re: Need help with winSCP
« Reply #3 on: September 01, 2017, 11:55:44 am »
I got it...
It was missing this line:

objSessionOptions.SshPrivateKeyPath = "Z:\mypath\Private.ppk"