scala-ssh
scala-ssh copied to clipboard
Stuck at "Closing connection" state after upload file
SSH("host", h) { client =>
client.upload(file.getAbsolutePath, file.getName)
}
Here's output log.
11:09:44.452 [main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle registration succeeded
11:09:44.490 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
11:09:44.509 [main] INFO com.decodified.scalassh.package$RichSshClient - Connecting to myhost.com:22 ...
11:09:44.557 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_9_2
11:09:44.606 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
11:09:44.826 [main] INFO com.decodified.scalassh.package$RichSshClient - Authenticating to myhost.com:22 using jerry.cm ...
11:09:45.326 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request to exec `scp -t -r -p 'dummy.txt'`
11:09:45.473 [main] INFO net.schmizz.sshj.common.StreamCopier - 0.0048828125 KiB transferred in 0.0 seconds (Infinity KiB/s)
11:09:45.653 [main] INFO com.decodified.scalassh.SshClient - Closing connection to myhost.com:22 ...
The application doesn't close. It will be closed automatically if I just use client.exec. Should I close my application manually?
I have the same issue.
Yeah, I had a similar issue myself but wasn't able to dig up the root cause at the time due to capacity constraints.
For me, this also applies to file downloads. When I execute the download test case, the connection hangs at close. Also the try-finally seems not necessary, since the connection is closed automatically.
got same issue with client.upload(), a simple app never exits, probably due to this thread:
"reader" prio=10 tid=0x00007f70ac3bf000 nid=0x3fb7 runnable [0x00007f70a046d000] java.lang.Thread.State: RUNNABLE at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:152) at java.net.SocketInputStream.read(SocketInputStream.java:122) at net.schmizz.sshj.transport.Reader.run(Reader.java:50)
Looks like this fixes it, ScpTransferable:
def fileTransfer[T](fun: SCPFileTransfer ⇒ T)(implicit listener: TransferListener = new LoggingTransferListener()): Validated[T] =
authenticatedClient.right.flatMap { client ⇒
protect("SCP file transfer failed") {
val transfer = client.newSCPFileTransfer()
transfer.setTransferListener(listener)
try {
fun(transfer)
} finally {
client.close()
}
}
}