Setting ASCII mode in Jsch

I need to overcome the Unix - Windows format file (LF to CRLF) I currently have. The ftp client I'm using is Jsch from Jcraft.

The online documentation is very bare, although I came across a flag that can be set



which activates ASCII mode, but I can't see where I should set this in the code itself, and I don't see it mentioned in these Javadocs

Below is my own attempted workaround. The "Recently Added" line shows how I take a file and convert it to an ASCII encoded string, which I then pass using the putSetp method. Initially, I would just put the file.

final JSch jsch = new JSch();
final Session session = jsch.getSession(username, host);

final Channel channel = session.openChannel("sftp");
final ChannelSftp channelSftp = (ChannelSftp) channel;;

File file = new File(pathName);
String content = FileUtils.readFileToString(file, "US-ASCII"); // Newly Added
channelSftp.put(content, fileToTransfer.getName());


Please note that I have skipped exception handling and other methods just for clarity of the code snippet.

Will this workaround be successful, or does Jsch seemingly default binary mode override the ASCII encoded string and pass it on as usual?

I'll check it out, I'm just wondering if any of you can tell right away? Or really knew how / where to set the Text_Mode flag! :)

Also, the Jsch version I am using is jsch-0.1.49.jar.


source to share

1 answer

The text mode flag was added to SFTP version 4. Currently Jsch supports SFTP version 3 , which does not specify a text field, mode flag.

You can see the SFTP specification changelog here . RFC for protocol version 3 here . Please note that OpenSSH, the most widely used SFTP server, only supports protocol version 3 and does not support line terminator translation. Therefore, having a flag in Jsch might not be very useful.



All Articles