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

Hi, While sftp'ing the files, how can we set the transfer mode (ASCII/Binary) of the file? I am sftp'ing the file with out using any modules(Net::SFTP). $sftp_cmd = `sftp $usr\@$address <<EOF \n cd $remote_dir \nbye \nEOF`; Can someone please help on how can I set the transfer mode ? Thanks in Advance!!!
  • Comment on In Perl, How to pass the File Transfermode in SFTP

Replies are listed 'Best First'.
Re: In Perl, How to pass the File Transfermode in SFTP
by stevieb (Canon) on May 25, 2016 at 17:04 UTC

    As far as I know, you can't. SFTP works on top of SSH, where you can't set the transfer mode. It'll always be binary.

    This feels like an XY Problem. What is the issue you're seeing?

      Thanks for the Reply! I am trying to set the transfer mode in my sftp process. But I could not find any options. Hence, seeking help from all of you!
Re: In Perl, How to pass the File Transfermode in SFTP
by Mask (Pilgrim) on May 25, 2016 at 17:03 UTC
    It depends on your SFTP client and SFTP protocol version you are using.
    By default SFTP transfer is binary, TEXT mode is supported from version 4 of the protocol.
    What OS and what client are you using?
      Thanks for the reply! As part of the initial requirement we are sending the files through FTP using Net::FTP module. We are now, updating the process to SFTP and we cant have Net::SFTP module installed. So I am looking for some help how can we set the transfer mode before sftp'ing the files. Thanks again!
        All this is in Perl. Processing the files from Windows.
Re: In Perl, How to pass the File Transfermode in SFTP
by haukex (Archbishop) on May 25, 2016 at 18:22 UTC

    Hi Yedu,

    As others have already pointed out, SFTP defaults to binary mode, in fact older versions of the protocol don't even have an "ASCII mode", so if you don't see the option in your client you probably won't be able to set it.

    Do you really need to transfer files in ASCII mode?

    If so, you will probably have to implement the necessary conversions (usually line endings) outside of SFTP, before or after transfer.

    Regards,
    -- Hauke D

      Hi All, Thanks for your reply. Is there any other possibility to set the transfer mode to ASCII using Net::SFTP::Foreign module or any other modules in the SFTP?
        Also, just to update you, I am using SFTP version3.