Search code examples
perlsftpwinscpwinscp-net

Perl - Win32::OLE::const error


I’m trying to use WinSCP for SFTP with a Perl script. I’m pretty much using the code off of the WinSCP site verbatim. But I’m getting the following error:

Win32::OLE::CONST->Load: No or invalid type library name at test.pl line 12. Win32::OLE(0.1712): GetOleTypeLibObject() Not a Win32::OLE::TypeLib object at C:/Perl/lib/Win32/OLE/Const.pm line 49.

Does anyone know what could be causing this?

My code:

use Win32::OLE;
use Win32::OLE::Const;
use Win32::OLE::Variant;
 
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
my $session = Win32::OLE->new('WinSCP.Session');
 
my $consts = Win32::OLE::Const->Load($session);
 
my $sessionOptions = Win32::OLE->new('WinSCP.SessionOptions');

Solution

  • Make sure you have registered WinSCP .NET assembly for COM:

    %WINDIR%\Microsoft.NET\Framework\<version>\RegAsm.exe WinSCPnet.dll /codebase /tlb