Post a reply

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

peDantic

Re: SynchronizeDirectories Method Perl Example

Hi,
thanks for the initiative.
Example 3 (part):
my $synchronizationResult = $session->SynchronizeDirectories($consts->{'SynchronizationMode_Local'}, 'c:\\user\\home\\', '/home/ftp/', FALSE, FALSE, $consts->{'SynchronizationCriteria_Time'}, $transferOptions);

That code snippet works for us.
martin

Re: SynchronizeDirectories Method Perl Example

peDantic wrote:

thanks for the answer. I followed the link and tried to implement several examples in vain:

As I've asked you already in my very first post: Can you be more specific?

Is a variable $synOptions necessary for SynchronizeDirectories?

There's no WinSCP.SynchronizeDirectories class. And you do not use $synOptions variable anywhere anyway. So that code is wrong and useless.

Example 2 (part):
my $transferOptions = Win32::OLE->new('WinSCP.TransferOptions');
$transferOptions->{'TransferMode'} = $consts->{'TransferMode_Binary'};
$transferOptions->{'SynchronizationMode'} = $consts->{'SynchronizationMode_Local'};

TransferOptions class has no SynchronizationMode property.
peDantic

Re: SynchronizeDirectories Method Perl Example

martin wrote:

The link, I've posted, shows how to use .NET/COM enumerations in Perl. Did you follow the link? Just use the same syntax you are already using for Protocol.Ftp and TransferMode.Binary:

$session->SynchronizeDirectories($consts->{'SynchronizationMode_Local'}, ...



Hi Martin,
thanks for the answer. I followed the link and tried to implement several examples in vain:

Example 1 (part):
my $synOptions = Win32::OLE->new('WinSCP.SynchronizeDirectories');
$synOptions->{'SynchronizationMode'} = $consts->{'SynchronizationMode_Local'};
# $synOptions->{'SynchronizeDirectories'} = $consts->{'SynchronizationMode_Local'};
 
my $synchronizationResult = $session->SynchronizeDirectories($consts->{'SynchronizationMode_Local'}, '/user/home/', 'c:\\user\\data\\', $transferOptions);


Is a variable $synOptions necessary for SynchronizeDirectories?


Example 2 (part):
my $transferOptions = Win32::OLE->new('WinSCP.TransferOptions');
$transferOptions->{'TransferMode'} = $consts->{'TransferMode_Binary'};
$transferOptions->{'SynchronizationMode'} = $consts->{'SynchronizationMode_Local'};
 
my $transferResult = $session->SynchronizeDirectories($consts->{'SynchronizationMode_Local'}, '/user/home/', 'c:\\user\\data\\', $transferOptions);
martin

Re: SynchronizeDirectories Method Perl Example

The link, I've posted, shows how to use .NET/COM enumerations in Perl. Did you follow the link? Just use the same syntax you are already using for Protocol.Ftp and TransferMode.Binary:

$session->SynchronizeDirectories($consts->{'SynchronizationMode_Local'}, ...
peDantic

Re: SynchronizeDirectories Method Perl Example

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


Hi Martin,
thanks for quick respond.
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";
}
peD4ntic

SynchronizeDirectories Method Perl Example

Good evening,
the example for Perl https://winscp.net/eng/docs/library_perl#example works well.
However, I have to syncronize the files and can not find a suitable method that works under Perl.

Example snippet (does not work)
my $transferResult =
$session->SynchronizeDirectories(SynchronizationMode.Local, '/home/user/', 'd:\\toupload\\*', FALSE, $transferOptions);

Could anyone help me, please?
An SynchronizeDirectories Method Example for Perl would be great - Thanks in advance!

Best regards