Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

RamAjay

I figured it out the error. I was calling Win32::OLE->Option(Warn => sub {goto CheckError}); from the sub routine which was calling the session->Open. I had to move that out of the sub routine to capture the errors.

i.e.
Win32::OLE->Option(Warn => sub {goto CheckError});
sub sftp{
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
my $session = Win32::OLE->new('WinSCP.Session') || die "Can't create winscp sessoion: ", Win32::OLE->LastError;
my $consts = Win32::OLE::Const->Load($session);
my $sessionOptions = Win32::OLE->new('WinSCP.SessionOptions')|| die "Can't open winscp
sessoionOptions: ", Win32::OLE->LastError;
$sessionOptions->{'Protocol'} = $consts->{'Protocol_Sftp'};
$sessionOptions->{'HostName'} = $Server;
$sessionOptions->{'UserName'} = $UserId;
$sessionOptions->{'Password'} = $SSHPassword;
$sessionOptions->{'SshHostKeyFingerprint'} = $SSHHostKeyFingerPrint;

$session->Open( $sessionOptions);
my $OLEConnectionError = Win32::OLE->LastError;
if ("$OLEConnectionError" ne "0")
{
print "$OLEConnectionError","\n";
exit 13;
}

}
Ram

Hi golfkilo,

Tried plugging in the solution you posted for error handling. The perl script throws an error on Check Error. i.e. Can't find label CheckError

Would you be able to share some sample codes to catch the session open or transfer result errors please?

Win32::OLE->Option(Warn => sub {goto CheckError});

And then have something like this at the end of your script...
CheckError:
#Just an example what you might want to do...
my $oleerror = Win32::OLE->LastError;
print "$oleerror\n";
$session->Dispose();
exit;[/quote]
martin

Re: Throwing errors under Perl

Thanks for sharing this.
golfkilo

I think I have solved it myself :)

The sample code needs some amending...

At the beginning it needs to add for example:
Win32::OLE->Option(Warn => sub {goto CheckError});

And then have something like this at the end of your script...
CheckError:
#Just an example what you might want to do...
my $oleerror = Win32::OLE->LastError;
print "$oleerror\n";
$session->Dispose();
exit;
golfkilo

Throwing errors under Perl

Hi,

I have a problem with error handling in perl
All the latest versions of WinSCP, ActivePerl, Perl modules...

I am using this example with sftp server running under Centos. The Windows machine is 2012R2
https://winscp.net/eng/docs/library_perl#example

Well all works apart from error handling...

For error handling testing I tried non existing file names, etc

$transferResult->Check();

Nothing happens here... Nada. What am I missing?

I did the same tests with the powershell example script.. And it works exactly as expected!
( https://winscp.net/eng/docs/library_powershell#example )
It throws the errors like a dream.

The problem is I have to use perl... any idea what could be wrong? I suspect something in Win32::OLE;

Anyone got an idea?