sshj
sshj copied to clipboard
"TransportException: Broken transport; encountered EOF" connecting to a new third party SFTP
Hi,
A third party was using FTP and is switching to SFTP. I can connect to their new server using plain sftp command-line (on Ubuntu) but cannot connect to it using sshj. All I'm getting is a "Broken transport; encountered EOF" error.
Here is a minimal code exhibiting the issue. Note that I tried disabling server validation to rule out security issues, to no avail:
import java.io.IOException;
import java.security.PublicKey;
import java.util.List;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPClient;
import net.schmizz.sshj.sftp.RemoteResourceInfo;
import net.schmizz.sshj.transport.verification.HostKeyVerifier;
public class SFTPExample {
public static void main(String[] args) {
if (args.length < 4) {
System.err.println("Usage: SFTPExample host login password remoteDir");
System.exit(-1);
}
String host = args[0];
String username = args[1];
String password = args[2];
String remoteDir = args[3];
SSHClient sshClient = new SSHClient();
try {
// Disable host key verification
sshClient.addHostKeyVerifier(new HostKeyVerifier() {
public boolean verify(String hostname, int port, PublicKey publicKey) {
return true;
}
public List<String> findExistingAlgorithms(String hostname, int port) {
return null;
}
});
// Connect to the remote SFTP server
sshClient.connect(host);
sshClient.authPassword(username, password);
// Open an SFTP session
SFTPClient sftpClient = sshClient.newSFTPClient();
// List files in the remote directory
List<RemoteResourceInfo> fileList = sftpClient.ls(remoteDir);
// Print the list of files
System.out.println("Listing files in: " + remoteDir);
for (RemoteResourceInfo file : fileList) {
System.out.println(file.getName());
}
// Close the SFTP client
sftpClient.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
// Close the SSH client
if (sshClient.isConnected()) {
sshClient.disconnect();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
The log is:
[main] INFO net.schmizz.sshj.transport.random.JCERandom - Creating new SecureRandom.
[main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0.39.0
[main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-mod_sftp
[sshj-Reader-/54.185.84.253:22-1727803034330] ERROR net.schmizz.sshj.transport.TransportImpl - Dying because - Broken transport; encountered EOF
net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
at net.schmizz.sshj.transport.Reader.run(Reader.java:58)
[sshj-Reader-/54.185.84.253:22-1727803034330] INFO net.schmizz.sshj.transport.TransportImpl - Disconnected - UNKNOWN
[main] ERROR net.schmizz.concurrent.Promise - <<service accept>> woke to: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
at net.schmizz.sshj.transport.Reader.run(Reader.java:58)
When increasing the trace level, here is the part where it fails:
...
[sshj-Reader-/54.185.84.253:22-1727802635949] DEBUG net.schmizz.concurrent.Promise - Clearing <<kexinit sent>>
[sshj-Reader-/54.185.84.253:22-1727802635949] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `SOME`
[main] DEBUG net.schmizz.sshj.SSHClient - Key exchange took 0.386 seconds
[main] DEBUG net.schmizz.concurrent.Promise - Clearing <<service accept>>
[main] DEBUG net.schmizz.sshj.transport.TransportImpl - Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
[main] TRACE net.schmizz.sshj.transport.Encoder - Encoding packet #3: 05 00 00 00 0c 73 73 68 2d 75 73 65 72 61 75 74 68
[main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<service accept>>
[sshj-Reader-/54.185.84.253:22-1727802635949] ERROR net.schmizz.sshj.transport.TransportImpl - Dying because - Broken transport; encountered EOF
net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
at net.schmizz.sshj.transport.Reader.run(Reader.java:58)
...
Note: I'm using sshj-0.39.0, bcprov-jdk18on-1.78.1 and eddsa-0.3.0.jar
Any idea what could cause the issue and how to solve it ? Am I doing something wrong :-) ?
KR, Vincent