in reply to Re^2: Net:SSH2 connects, but scp_get fails
in thread Net:SSH2 connects, but scp_get fails
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):
with the more verbose (but more correct) blockprintf("# scp_get(%s,%s)\n", $myFile, $localDir . "\\$myFile"); $rc=$ssh2->scp_get($myFile, $localDir . "\\$myFile"); printf("# rc=%s\n", defined($rc)?$rc:"<UNDEFINED>");
# 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
|
|---|