tharagleb
I have managed to write a Perl program that makes an FTP connection and uploads several files. When I was done I tried to write a routine that would read the directory and show me the files in it. The problem I seem to be having is that after I issue the ReadDirectory method my {Items} looks like this (using Data::Dump):
bless({
# tied Win32::OLE::Tie
Count => 16,
Item => undef,
}, "Win32::OLE")
Although the count, 16, is correct there are no actual items in {Item}.
I wrote a program that just does the connection and attempts to read the directory, the program, output and log file are below.
As a side note the ReadDirectoryRaw method works perfectly and creates a file with the directory info in it.
Any help would be greatly appreciated!
-Alan
[Post editted to change ReadDirectoryFromCommand() to ReadDirectory(), the results are identical.]
Here is my program:
=============
#///////////////////////////////////////////////////////////////////////////////////
#//
#// Testdir.pl
#//
#///////////////////////////////////////////////////////////////////////////////////
use Win32::OLE;
use Win32::OLE::Variant;
use Data::Dump qw(dump pp ddx);
# ==========================================
# Setup the FTP connection
# ==========================================
$ftp = Win32::OLE->new('sfFTPLib.FTPConnectionMTA');
$ftp->{Host} = "xxx";
$ftp->{Username} = "xxx";
$ftp->{Password} = "xxx";
$ftp->{Port} = 21;
$ftp->{Passive} = 1; # Use Passive mode.
$ftp->{MLST} = 1; # Use the MLSD command to list directories
$ftp->{Protocol} = 2; # FTP over SSL Explict
$ftp->{Logfile} = "log.txt";
$ftp->{LISTOption} = 1;
unlink("log.txt");
# ==========================================
# Make the FTP connection
# ==========================================
print "\nAttempting to connect ...\n";
if ($ftp->Connect() == 0)
{
if ($ftp->ChangeDirectory("test") == 0)
{
print "Change directory worked\n";
}
else
{
die "Change directory failed\n";
}
}
else
{
die "Could not connect.\n";
}
$dir = $ftp->{WorkingDirectory};
print "\nCurrent directory is: $dir \n\n";
print "Reading server directory\n";
if ($ftp->ReadDirectory() == 0)
{
$temp = $ftp->{Items};
print "\nDump:\n" . pp($temp) . "\n\n";
}
$ftp->Close();
Here is the output:
============
H:\Perl\programs>perl testdir.pl
Attempting to connect ...
Change directory worked
Current directory is: /xxx/test
Reading server directory
Dump:
bless({
# tied Win32::OLE::Tie
Count => 16,
Item => undef,
}, "Win32::OLE")
And here is the log file:
================
[20090130 13:37:38] SmartFTP FTP Library v1.5.17.12
[20090130 13:37:38] Resolving host name "xxx"
[20090130 13:37:38] Connecting to xxx Port: 21
[20090130 13:37:38] Connected to xxx
[20090130 13:37:39] 220 xxx FTPS Server
[20090130 13:37:39] AUTH TLS
[20090130 13:37:39] 234 AUTH TLS successful
[20090130 13:37:39] Connected. Exchanging encryption keys...
[20090130 13:37:42] Session Cipher: 128 bit AES
[20090130 13:37:42] TLS encrypted session established.
[20090130 13:37:42] Command channel protection set to Private.
[20090130 13:37:42] PBSZ 0
[20090130 13:37:42] 200 PBSZ 0 successful
[20090130 13:37:42] USER xxx
[20090130 13:37:42] 331 Password required for xxx.
[20090130 13:37:42] PASS xxx
[20090130 13:37:44] 230 User xxx logged in.
[20090130 13:37:44] SYST
[20090130 13:37:44] 215 UNIX Type: L8
[20090130 13:37:44] Detected Server Type: UNIX
[20090130 13:37:44] RTT: 29.795 ms
[20090130 13:37:44] FEAT
[20090130 13:37:44] 211-Features:
[20090130 13:37:44] MDTM
[20090130 13:37:44] REST STREAM
[20090130 13:37:44] SIZE
[20090130 13:37:44] AUTH TLS
[20090130 13:37:44] PBSZ
[20090130 13:37:44] PROT
[20090130 13:37:44] 211 End
[20090130 13:37:44] PWD
[20090130 13:37:45] 257 "/xxx" is current directory.
[20090130 13:37:45] CWD test
[20090130 13:37:45] 250 CWD command successful
[20090130 13:37:45] PWD
[20090130 13:37:45] 257 "/xxx/test" is current directory.
[20090130 13:37:45] TYPE I
[20090130 13:37:45] 200 Type set to I
[20090130 13:37:45] PROT C
[20090130 13:37:45] 200 Protection set to Clear
[20090130 13:37:45] PASV
[20090130 13:37:45] 227 Entering Passive Mode (xxx).
[20090130 13:37:45] Opening data connection to xxx Port: 40000
[20090130 13:37:45] LIST
[20090130 13:37:45] 150 Opening ASCII mode data connection for file list
[20090130 13:37:45] 1072 bytes transferred. (16.8 KB/s) (62 ms)
[20090130 13:37:45] 226 Transfer complete.
[20090130 13:37:45] Client closed the connection.
bless({
# tied Win32::OLE::Tie
Count => 16,
Item => undef,
}, "Win32::OLE")
Although the count, 16, is correct there are no actual items in {Item}.
I wrote a program that just does the connection and attempts to read the directory, the program, output and log file are below.
As a side note the ReadDirectoryRaw method works perfectly and creates a file with the directory info in it.
Any help would be greatly appreciated!
-Alan
[Post editted to change ReadDirectoryFromCommand() to ReadDirectory(), the results are identical.]
Here is my program:
=============
#///////////////////////////////////////////////////////////////////////////////////
#//
#// Testdir.pl
#//
#///////////////////////////////////////////////////////////////////////////////////
use Win32::OLE;
use Win32::OLE::Variant;
use Data::Dump qw(dump pp ddx);
# ==========================================
# Setup the FTP connection
# ==========================================
$ftp = Win32::OLE->new('sfFTPLib.FTPConnectionMTA');
$ftp->{Host} = "xxx";
$ftp->{Username} = "xxx";
$ftp->{Password} = "xxx";
$ftp->{Port} = 21;
$ftp->{Passive} = 1; # Use Passive mode.
$ftp->{MLST} = 1; # Use the MLSD command to list directories
$ftp->{Protocol} = 2; # FTP over SSL Explict
$ftp->{Logfile} = "log.txt";
$ftp->{LISTOption} = 1;
unlink("log.txt");
# ==========================================
# Make the FTP connection
# ==========================================
print "\nAttempting to connect ...\n";
if ($ftp->Connect() == 0)
{
if ($ftp->ChangeDirectory("test") == 0)
{
print "Change directory worked\n";
}
else
{
die "Change directory failed\n";
}
}
else
{
die "Could not connect.\n";
}
$dir = $ftp->{WorkingDirectory};
print "\nCurrent directory is: $dir \n\n";
print "Reading server directory\n";
if ($ftp->ReadDirectory() == 0)
{
$temp = $ftp->{Items};
print "\nDump:\n" . pp($temp) . "\n\n";
}
$ftp->Close();
Here is the output:
============
H:\Perl\programs>perl testdir.pl
Attempting to connect ...
Change directory worked
Current directory is: /xxx/test
Reading server directory
Dump:
bless({
# tied Win32::OLE::Tie
Count => 16,
Item => undef,
}, "Win32::OLE")
And here is the log file:
================
[20090130 13:37:38] SmartFTP FTP Library v1.5.17.12
[20090130 13:37:38] Resolving host name "xxx"
[20090130 13:37:38] Connecting to xxx Port: 21
[20090130 13:37:38] Connected to xxx
[20090130 13:37:39] 220 xxx FTPS Server
[20090130 13:37:39] AUTH TLS
[20090130 13:37:39] 234 AUTH TLS successful
[20090130 13:37:39] Connected. Exchanging encryption keys...
[20090130 13:37:42] Session Cipher: 128 bit AES
[20090130 13:37:42] TLS encrypted session established.
[20090130 13:37:42] Command channel protection set to Private.
[20090130 13:37:42] PBSZ 0
[20090130 13:37:42] 200 PBSZ 0 successful
[20090130 13:37:42] USER xxx
[20090130 13:37:42] 331 Password required for xxx.
[20090130 13:37:42] PASS xxx
[20090130 13:37:44] 230 User xxx logged in.
[20090130 13:37:44] SYST
[20090130 13:37:44] 215 UNIX Type: L8
[20090130 13:37:44] Detected Server Type: UNIX
[20090130 13:37:44] RTT: 29.795 ms
[20090130 13:37:44] FEAT
[20090130 13:37:44] 211-Features:
[20090130 13:37:44] MDTM
[20090130 13:37:44] REST STREAM
[20090130 13:37:44] SIZE
[20090130 13:37:44] AUTH TLS
[20090130 13:37:44] PBSZ
[20090130 13:37:44] PROT
[20090130 13:37:44] 211 End
[20090130 13:37:44] PWD
[20090130 13:37:45] 257 "/xxx" is current directory.
[20090130 13:37:45] CWD test
[20090130 13:37:45] 250 CWD command successful
[20090130 13:37:45] PWD
[20090130 13:37:45] 257 "/xxx/test" is current directory.
[20090130 13:37:45] TYPE I
[20090130 13:37:45] 200 Type set to I
[20090130 13:37:45] PROT C
[20090130 13:37:45] 200 Protection set to Clear
[20090130 13:37:45] PASV
[20090130 13:37:45] 227 Entering Passive Mode (xxx).
[20090130 13:37:45] Opening data connection to xxx Port: 40000
[20090130 13:37:45] LIST
[20090130 13:37:45] 150 Opening ASCII mode data connection for file list
[20090130 13:37:45] 1072 bytes transferred. (16.8 KB/s) (62 ms)
[20090130 13:37:45] 226 Transfer complete.
[20090130 13:37:45] Client closed the connection.