martin wrote:
"does not work" is pretty vague. Can you be more specific?
Though
SynchronizationMode.Local
is wrong. Check this:
https://winscp.net/eng/docs/library_perl#enums
I've tried using SynchronizationMode.Local, but have no idea how to implement it in Perl (try&error). When i start the script with the SynchronizationMode, the variable "$transferResult-> Check ();" no value (undef) returned.
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const;
use Win32::OLE::Variant;
use feature qw(switch);
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
use constant
{
TRUE => Variant(VT_BOOL, 1),
FALSE => Variant(VT_BOOL, 0)
};
sub session_Events()
{
my ($obj, $event, @args) = @_;
given ($event)
{
when ('FileTransferred')
{
my ($sender, $e) = @args;
printf "%s => %s\n", ( $e->{'FileName'}, $e->{'Destination'} );
}
}
}
# Load constants
# Setup session options
my $session = Win32::OLE->new('WinSCP.Session');
my $consts = Win32::OLE::Const->Load($session);
my $sessionOptions = Win32::OLE->new('WinSCP.SessionOptions');
$sessionOptions->{'Protocol'} = $consts->{'Protocol_Ftp'};
$sessionOptions->{'HostName'} = '127.0.0.1';
$sessionOptions->{'UserName'} = 'TEST';
$sessionOptions->{'Password'} = 'TESTPW';
# Connect
$session->Open($sessionOptions);
# Synchronize files
my $transferOptions = Win32::OLE->new('WinSCP.TransferOptions');
$transferOptions->{'TransferMode'} = $consts->{'TransferMode_Binary'};
my $transferResult = $session->SynchronizeDirectories(SynchronizationMode Local, '/home/martin/', 'c:\\usr\\test\\', $transferOptions);
# Throw on any error
$transferResult->Check();
# Print results
my $items = Win32::OLE::Enum->new($transferResult->{'Transfers'});
my $item;
while (defined($item = $items->Next))
{
print $item->{'FileName'} . "\n";
}