Reputation: 11
I wanted to download files using FTP from a server. I can do it properly through command-line and want the same thing using Java. This is my code
session = jsch.getSession(user, server, 22);
session.setPassword(pass);
session.setTimeout(10000);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
**channel.connect();**
channel.disconnect();
session.disconnect();
Problem is when the channel is connecting i.e channel.connect
and I am getting an error:
com.jcraft.jsch.JSchException: 4: Received message is too long: 1619214428
at com.jcraft.jsch.ChannelSftp.start(ChannelSftp.java:242)
at com.jcraft.jsch.Channel.connect(Channel.java:200)
at com.jcraft.jsch.Channel.connect(Channel.java:144)
at com.cca.processor.FTPProcessor.main(FTPProcessor.java:54)
Caused by: 4: Received message is too long: 1619214428
at com.jcraft.jsch.ChannelSftp.start(ChannelSftp.java:214)
... 3 more
Upvotes: 1
Views: 5836
Reputation: 202222
As you commented yourself, you cannot connect with any SFTP client.
So there's nothing wrong with your JSch/Java code.
The error occurs only after an SSH authentication, when an SFTP session is starting.
It's typically caused by some startup shell script printing a message, and thus breaking the SFTP protocol.
The number in the error (1619214428) is then the first four characters in the message interpreted as a 32-bit number.
But in your case it does not really seem to be a readable text (were it, WinSCP would display the readable form too). The number stands for 6083405C
in hexadecimal notation, what is <.(@
(where the dot stands for a character outside of ASCII table).
See also WinSCP documentation for the error message:
https://winscp.net/eng/docs/message_large_packet
Still, it's the server that is broken, not your code. You should contact your server administrator or review startup shell scripts of your account.
Though you claim you were able to use FTP from command-line and WinSCP. So maybe you should actually use FTP (or better FTPS), not SFTP. You cannot use JSch for FTP (or FTPS). You can use Apache Commons FTPClient
for example.
Upvotes: 2