mytutorial has asked for the wisdom of the Perl Monks concerning the following question:

My conversion to binary using sftp is failing in my perl script. Can someone help? A portion of the perl script is below. Thank You!

use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new($remotehost, %args) or $newerr += 1; if($newerr){ $err = $sftp->error; push @ERRORS, "Can't sftp to $remotehost - Error: $err"; myerr(); } else { $sftp->setcwd("$remotedir$file_ext") or $newerr=1; if($newerr){ $err = $sftp->error; push @ERRORS, "Can't cd to $remotedir - Error: $er +r"; myerr(); } else { foreach(@file) { $sftp->binary; $sftp->put("$OUTDIR$_", "$_") or $newerr = 1;

Replies are listed 'Best First'.
Re: $sftp->binary failing
by NetWallah (Canon) on Aug 13, 2014 at 03:38 UTC
    Neither Net::SFTP nor Net::SFTP::Foreign have a documented "binary" method.

    (Perhaps you expected them to, because Net::FTP does.)

    Net::SFTP::Foreign allows you to pass a reference to a file handle in the "put" method.

    It is possible to open this file handle and "binmode" it, prior to passing it in - this will probably accomplish what you are attempting.

            Profanity is the one language all programmers know best.

Re: $sftp->binary failing
by salva (Canon) on Aug 13, 2014 at 16:33 UTC
    The transfer mode (text or binary) is a feature of FTP that doesn't have an equivalent on SFTP (mostly because the transformation can be done on the client side).

    Just remove the binary call from your code.

Re: $sftp->binary failing
by Anonymous Monk on Aug 13, 2014 at 00:45 UTC

    "Failing" is not an accurate enough description of the problem - are you getting error messages (if yes, which ones exactly?), is something else going wrong, etc.?. Please read and follow How do I post a question effectively?