Topic "Throwing errors under Perl"

Author Message
golfkilo
[View user's profile]

Joined: 2017-08-15
Posts: 2
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?
Advertisements
golfkilo
[View user's profile]

Joined: 2017-08-15
Posts: 2
I think I have solved it myself Smile

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;
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27083
Location: Prague, Czechia
Thanks for sharing this.
_________________
Martin Prikryl
Ram

Guest


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]
RamAjay

Guest


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;
}

}
Advertisements

You can post new topics in this forum

Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License