Topic "Perl, ListDirectory, Can't see files"

Author Message
Tharg
[View user's profile]
Donor
Joined: 2014-05-16
Posts: 2
Hi -

My WWinscp is V 5.5.3 (in the client).

I have been trying to use it with Perl and ftps.

I don't have direct access to the server (for logs etc).

My perl script, so far (based on an example), is :

Code:
use strict;
use warnings;
 
use Win32::OLE;
use Win32::OLE::Const;
use Win32::OLE::Variant;
 
use Data::Dumper;

use constant
{
    TRUE  => Variant(VT_BOOL, 1),
    FALSE => Variant(VT_BOOL, 0)
};

my $Host   = 'REDACTED';
my $User   = 'REDACTED';
my $Password   = 'REDACTED';


my $session = Win32::OLE->new('WinSCP.Session');
 
# Load constants
my $consts = Win32::OLE::Const->Load($session);
 
# Setup session options
my $sessionOptions = Win32::OLE->new('WinSCP.SessionOptions');
 
$sessionOptions->{'Protocol'} = $consts->{'Protocol_Ftp'};
$sessionOptions->{'FtpSecure'} = $consts->{'FtpSecure_ExplicitSsl'};
$sessionOptions->{'FtpMode'} = $consts->{'FtpMode_Passive'};
$sessionOptions->{'HostName'} = $Host;
$sessionOptions->{'UserName'} = $User;
$sessionOptions->{'Password'} = $Password;
$sessionOptions->{'TransferMode'} = $consts->{'TransferMode_Binary'};
 
# Connect
$session->Open($sessionOptions);

my $Files = $session->ListDirectory("/20140506")->Files();

while ( defined( my $File = $Files->Next ) ){
   printf STDOUT ("%s\n", "..." );
   printf STDOUT ("%s\n", $File->Name );
   printf STDOUT ("%s\n", $File->Name() );
   printf STDOUT ("%s\n", $File->Length() );
}


And I never find any files. If I try to transfer a file on to the server instead, this works fine.

I'm afraid that although I'm reasonably good with Perl, I'm not in any way confident with using it in this way, with Win32::OLE etc. I don't know how to check for errors here or whatever.

I can connect using the WinSCP client and see file lists etc.

Thanks for any help!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
I'm not Perl expert.
But did you try to access the Files collection the way Transfers collection is accessed on this example:
http://winscp.net/eng/docs/library_perl#example

I.e.
Code:
my $directory = $session->ListDirectory("/20140506");
my $items = Win32::OLE::Enum->new($directory->{'Files'});

_________________
Martin Prikryl
Tharg
[View user's profile]
Donor
Joined: 2014-05-16
Posts: 2
Thank you so much, this has now worked.

I have struggled with getting perl's NET::FTPSSL working for some time, and finally found that the server I'm connecting to requires re-use of the data connection, which that library does not support.

Now it looks like, with WinSCP, I will be able to get everything working as I need it to. I made a donation - have a drink or a pizza on me.
Advertisements

You can post new topics in this forum






Search Site

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