kilaru rajeev wrote:
> 
> I have a situation where I need to open a sftp connection, need to pull the
> file and have to verify receipt of local file after that have to rename the
> file in remote dir. For that, I wrote the following code. The code is giving
> the output given below and coming out of the program. But I could see the
> file in $logDir. Please let me know how I can fix the code.
> 
>   open (FH, "|sftp [EMAIL PROTECTED]") or exception ("Unable to open the sftp:
> $!");
>     foreach my $filename (@files) {
>       $localFile = makeFilePath( $logDir, $filename );
>       print( "Retrieving output file $filename" );
>       $remoteFile = makeFilePath($fileDir, $filename);
>       print FH "get $remoteFile $logDir\n";
>       FH->autoflush(1) ;
> *      die ( "Error retrieving output file: $localFile" ) if ( !-e
> $localFile);*
>       # To Rename the file to file.old
>       $oldFile = $remoteFile.".old";
>       print FH "rename $remoteFile $oldFile\n" or report "$!";
>       FH->autoflush(1);
>       push @dataFiles, $localFile;
>     }
> 
> Output:
> 
> Retrieving output file tissmAPI08220000.txt
> Error retrieving output file: /crdv8/logs/tissmAPI08220000.txt
> Pre-processing/data-mapping step reported failure on feed NAPI SM load
> sftp> Fetching /trading/tissmAPI08220000.txt to
> /crdv8/logs/tissmAPI08220000.txt
> sftp>

- You don't appear to have provided a password anywhere to the secure FTP server

- You need to set autoflush only once. That should be immediately the file
  handle is opened

- You have sent a 'get' command put have no way of know when the transfer is
  complete. Your program reports an error because it tests for the local file
  before the transfer can even start.

- What does makeFilePath do?

I suggest you should use the Net::SFTP module instead of opening a pipe to a
sftp command-line tool. You will have much better control over and monitoring of
the transfer that way. If you are using the utility you may as well simply
provide it with a command file and forget about Perl altogether.

If you would like some help with using Net::SFTP then please show the rest of
your program and we will be able to make some suggestions.

Rob

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to