Apache Mina SSHD slow download and failing connection using SCP

209 Views Asked by At

I have a Problem when trying to download large files through SCP. I use Apache Mina SSHD in Java. For small files it works as intended, but when I try to download a large file, the download is really slow. After arround 8-10 minutes and downloading 60-70% Apache Mina fails with following error Message:

Error: write(ChannelOutputStream[ChannelExec[id=0, recipient=0]-ClientSessionImpl[user@server/ip-address:22]] SSH_MSG_CHANNEL_DATA) len=1 - channel already closed

I set the SSHD-Log on the destination to debug, but nothing gets logged when the download fails. The weird part: when I try downloading the file through SCP as a command-prompt or when using SFTP in Mina instead, the file completely downloads withouth problems and within arround 1 minute. So I doubt it's an issue with my server. But just to be sure I also ran scp with -l 5000 to simulate a slow as Mina download. But it also runs without issue.

Here is my code:

SshClient client = SshClient.setUpDefaultClient();
        
client.start()

HostConfigEntry host = new HostConfigEntry("", hostname, 22, username);   

try (ClientSession session = client.connect(host).verify().getSession()){ 

     session.auth().await();
            
     ScpClientCreator creator = ScpClientCreator.instance();
     ScpClient scpClient = creator.createScpClient(session);

     scpClient.download(
            remoteFilePath,
            localFilePath
     );
            
     session.close();
}
catch(Exception e) {
     System.out.println("Error: " + e.getMessage());
}
       
client.close();
0

There are 0 best solutions below