3

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');
Cory Kleiser
  • 1,969
  • 2
  • 13
  • 26
  • Why are you using WinSCP instead of Perl SFTP modules like [Net::SFTP::Foreign](http://search.cpan.org/~salva/Net-SFTP-Foreign-1.89/lib/Net/SFTP/Foreign.pm) – Andrey Apr 23 '18 at 13:19
  • I feel like this should be a comment. But short answer is I’m experimenting with multiple technologies including Net::SFTP::Foreign. – Cory Kleiser Apr 23 '18 at 17:44

1 Answers1

4

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

%WINDIR%\Microsoft.NET\Framework\<version>\RegAsm.exe WinSCPnet.dll /codebase /tlb
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/19524610) – Shikkediel Apr 23 '18 at 19:14
  • 3
    @Shikkediel Even though I somewhat expected to be blamed for posting a link-only question, I honestly believed that the answer stands on its own. All the OP needed to know was that the assembly needs to be registered for COM. How to register an assembly for COM is rather a common knowledge. And even if OP is not familiar with that, it is easy to be googled for. Anyway, I've added an example to my answer. – Martin Prikryl Apr 24 '18 at 05:51
  • 1
    Thank you for your answer. It easily solved my issue. :) – Cory Kleiser Apr 24 '18 at 07:06