That was it! Mixing SSH2 and SFTP commands is a bad thing.
For the sake of future Novices, I'm posting change required to get the sample script working:
Replace the original code block (around line 157):
printf("# scp_get(%s,%s)\n", $myFile, $localDir . "\\$myFile");
$rc=$ssh2->scp_get($myFile, $localDir . "\\$myFile");
printf("# rc=%s\n", defined($rc)?$rc:"<UNDEFINED>");
with the more verbose (but more correct) block
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# The previous code block was replaced with code to
# open remote and local files, then read the remote file
# and write it to the local file.
# The binmode() call is necessary because this is a
# Windows(tm)-to-UNIX transfer and line-endings must
# be preserved.
my $rfh; # Remote File Handle
$rfh = $sftp->open($sftpRemoteDir . "/" . $myFile);
if (defined($rfh))
{
if (open(LFH, ">$localDir\\$myFile"))
{
my $myLine;
# Force binary transfers to preserve line endings
# when transferring between Windows and UNIX.
binmode(LFH);
while ($myLine = <$rfh>)
{
printf(LFH "%s", $myLine);
}
close(LFH);
}
else
{
# ERROR: Could not open local file for transfer
printf("Could not open local file '%s' for transfer\n"
+,
$myFile);
}
}
else
{
# ERROR: Could not open remote file for transfer
printf("Could not open remote file '%s' for transfer\n",
$myFile);
}
Many thanks for your help! You saved me hours of banging my head against a wall!
Kevin
|