New Server Latest WinSCP, Perl Logic Not Working, Looking for Assistance
Hello Martin & WinSCP Support,
I have a series of Perl scripts on some servers that I'm replacing, with the latest version of WinSCP, minimal code changes.
I'm running into an issue with scripts that use the .Net Assembly, and looking for your assistance.
The following logic works on the old servers, but I'm getting errors with the new servers, after registering the .NET Assembly 32-bit and 64-bit objects, per https://winscp.net/eng/docs/library_install "Registering for COM":
Code, with lines where the errors occur repeated at end, with their errors, seem to maybe point to a syntax change needed somewhere?
I did notice that on the examples on the WinSCP site, the former Perl example to enumerate files does not appear to be there any longer (only PowerShell, VB, others).
CODE:
From the code above, this line generates no error, am assuming it successfully finds the directory I'm trying to peruse:
But this line, unchanged from program on older versions of WinSCP calls via Perl:
Generates the error:
Generates the error:
And then trying to enumerate the files in it as:
Would now cause this error?
I have a series of Perl scripts on some servers that I'm replacing, with the latest version of WinSCP, minimal code changes.
I'm running into an issue with scripts that use the .Net Assembly, and looking for your assistance.
The following logic works on the old servers, but I'm getting errors with the new servers, after registering the .NET Assembly 32-bit and 64-bit objects, per https://winscp.net/eng/docs/library_install "Registering for COM":
Code, with lines where the errors occur repeated at end, with their errors, seem to maybe point to a syntax change needed somewhere?
I did notice that on the examples on the WinSCP site, the former Perl example to enumerate files does not appear to be there any longer (only PowerShell, VB, others).
CODE:
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE); my $session = Win32::OLE->new('WinSCP.Session') || warn "Can't create winscp session: ", Win32::OLE->LastError; my $consts = Win32::OLE::Const->Load($session); my $sessionOptions = Win32::OLE->new('WinSCP.SessionOptions')|| die "Can't open winscp session Options: ", Win32::OLE->LastError; $sessionOptions->{'Protocol'} = $consts->{'Protocol_Sftp'}; $sessionOptions->{'HostName'} = $ProgramRemoteSFTPSettings::RemoteSFTPServer; $sessionOptions->{'UserName'} = $ProgramRemoteSFTPSettings::USER; $sessionOptions->{'Password'} = $ProgramRemoteSFTPSettings::PASSWORD; $sessionOptions->{'SshHostKeyFingerprint'} = $ProgramRemoteSFTPSettings::DestServerFingerPrintKey; $session->Open($sessionOptions); my $directory = $session->ListDirectory("${ProgramRemoteSFTPSettings::RemoteSFTPDirectory}\/"); my $items = Win32::OLE::Enum->new($directory->{'Files'}); my $item; while (defined($item = $items->Next)) { my $FilePermissionsHash = $item->{'FilePermissions'}; my $FilePermissions = $FilePermissionsHash->{'Text'}; print "DEBUG\:\t\-\- File Name on SFTP Site \= " . $item->{'Name'} . "\n\-\- FILE DETAIL on SFTP Site \:\n File Length\: " . $item->{'Length'} . "\, File Permissions\: " . $FilePermissions . "\, File Last Write Mod Date\: " . $item->{'LastWriteTime'} . "\n"; if (($item->{'Name'} =~ /FileName01\_([^#]+)\.csv/i) || ($item->{'Name'} =~ /FileName02\_([^#]+)\.csv/i)) { push (@FileContent::FilesOnSFTPSite,"$item->{'Name'}"); push (@FileContent::FilesOnSFTPSiteModTime, "$item->{'LastWriteTime'}"); print "DEBUG\:\tFILE = <$item->{'Name'}> Will be reviewed to see if it has been downloaded before\.\n"; if (($item->{'Name'} =~ /FileName01\_([^#]+)\.csv/i) && ($item->{'Name'} !~ /FileName02/i)) { $WeFoundFileName01 = 1; push (@FileContent::FilesOnSFTPSite,"$item->{'Name'}"); push (@FileContent::FilesOnSFTPSiteModTime, "$item->{'LastWriteTime'}"); print "DEBUG\:\tFILE = <$item->{'Name'}> Appears to be FileName01 for review\.\n"; } if ($item->{'Name'} =~ /FileName02\_([^#]+)\.csv/i) { $WeFoundFileName02 = 1; push (@FileContent::FilesOnSFTPSite,"$item->{'Name'}"); push (@FileContent::FilesOnSFTPSiteModTime, "$item->{'LastWriteTime'}"); print "DEBUG\:\tFILE = <$item->{'Name'}> Appears to be an File for review\.\n"; # print "DEBUG\:\tFILE = <$item->{'Name'}> Appears to be an FileName02 for review\.\n"; } } else { print "DEBUG\:\tFILE = <$item->{'Name'}> IS NOT either FileName01 or FileName02 for review\.\n"; if ($item->{'Name'} =~ /FileName/i) { print "DEBUG\:\tFILE = <$item->{'Name'}> IS NOT a FileName01 or FileName02 for review\, although it does match file naming convention (escalate for further review)\.\n"; $ProgramEmailSettings::HighEmailPriority = 1; push (@ProgramEmailSettings::HighEmailPriorityReason, "File $item->{'Name'} exists on SFTP Server, but does not meet file naming standards<BR>for this program. Please Review\!"); } } } $session->Dispose();
my $directory = $session->ListDirectory("${ProgramRemoteSFTPSettings::RemoteSFTPDirectory}\/");
my $items = Win32::OLE::Enum->new($directory->{'Files'});
And this following line: (While loop on the items returned from above error, so the previous line appears to be the issue)Win32::OLE(0.1713): GetOleObject() Not a Win32::OLE object at D:\Perl\PROGRAM\FilesGet.pl line X01.
while (defined($item = $items->Next))
Any idea as to why the setting ofCan't call method "Next" on an undefined value at D:\Perl\PROGRAM\FilesGet.pl line X02.
$directory
as:
And then trying to enumerate the files in it as:
my $directory = $session->ListDirectory("${ProgramRemoteSFTPSettings::RemoteSFTPDirectory}\/");
Thanks, Joe P.Win32::OLE(0.1713): GetOleObject() Not a Win32::OLE object at D:\Perl\PROGRAM\FilesGet.pl line 3830 (X01)?