SSHClient download does not terminate after a successful copy from a windows SSH server
I am downloading a file from windows machine to mac. This is the code I am using.
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.xfer.FileSystemFile;
import java.io.IOException;
public class SCPDownload {
public static void main(String[] args)
throws IOException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("arul-win64");
try {
ssh.authPassword("arul", "arul");
ssh.newSCPFileTransfer().download("C:/Users/arul/Downloads/staging/sample.pdf", new FileSystemFile("/Users/arul/Downloads/staging/remote/"));
} finally {
ssh.disconnect();
}
}
}
It successfully copies the file to mac, but the client does not exit the JVM. Took a thread dump which is shows the call waiting on this line in SCPDownloadClient.startCopy()
while (!(msg = engine.readMessage()).isEmpty());
Downloading a file from linux to mac works just fine and terminates JVM correctly. I am running Bitvise SSH Server on windows 7. Any idea why this is happening?
Debug log from SSHClient
/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java -Didea.launcher.port=7538 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/arul/github/sshclient-windows-bug/target/classes:/Users/arul/.m2/repository/com/hierynomus/sshj/0.11.0/sshj-0.11.0.jar:/Users/arul/.m2/repository/org/bouncycastle/bcpkix-jdk15on/1.51/bcpkix-jdk15on-1.51.jar:/Users/arul/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.51/bcprov-jdk15on-1.51.jar:/Users/arul/.m2/repository/com/jcraft/jzlib/1.1.3/jzlib-1.1.3.jar:/Users/arul/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar:/Users/arul/.m2/repository/org/slf4j/slf4j-log4j12/1.7.10/slf4j-log4j12-1.7.10.jar:/Users/arul/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar:/Applications/IntelliJ IDEA 13.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain SCPDownload
2015-01-28 09:48:55,818 [main] DEBUG net.schmizz.sshj.common.SecurityUtils - Trying to register BouncyCastle as a JCE provider
2015-01-28 09:48:56,364 [main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle registration succeeded
2015-01-28 09:48:56,416 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
2015-01-28 09:48:57,584 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_9_2
2015-01-28 09:48:57,590 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-5.29 FlowSsh: Bitvise SSH Server (WinSSHD) 6.21
2015-01-28 09:48:57,591 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `null`
2015-01-28 09:48:57,591 [main] DEBUG net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
2015-01-28 09:48:57,593 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<kexinit sent>> to `SOME`
2015-01-28 09:48:57,594 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<kex done>>
2015-01-28 09:48:57,596 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
2015-01-28 09:48:57,597 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Negotiated algorithms: [ kex=diffie-hellman-group14-sha1; sig=ssh-dss; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
2015-01-28 09:48:57,629 [reader] DEBUG net.schmizz.sshj.transport.kex.DHG14 - Sending SSH_MSG_KEXDH_INIT
2015-01-28 09:48:57,843 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
2015-01-28 09:48:57,843 [reader] DEBUG net.schmizz.sshj.transport.kex.DHG14 - Received SSH_MSG_KEXDH_REPLY
2015-01-28 09:48:57,883 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Trying to verify host key with net.schmizz.sshj.transport.verification.OpenSSHKnownHosts@6c9e5b31
2015-01-28 09:48:57,883 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
2015-01-28 09:48:57,883 [reader] DEBUG net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
2015-01-28 09:48:57,887 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<kexinit sent>> to `null`
2015-01-28 09:48:57,887 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<kex done>> to `SOME`
2015-01-28 09:48:57,887 [main] DEBUG net.schmizz.sshj.SSHClient - Key exchange took 0.296 seconds
2015-01-28 09:48:57,890 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<service accept>> to `null`
2015-01-28 09:48:57,890 [main] DEBUG net.schmizz.sshj.transport.TransportImpl - Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
2015-01-28 09:48:57,890 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<service accept>>
2015-01-28 09:48:58,203 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<service accept>> to `SOME`
2015-01-28 09:48:58,203 [main] DEBUG net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
2015-01-28 09:48:58,203 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `null`
2015-01-28 09:48:58,203 [main] DEBUG net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
2015-01-28 09:48:58,203 [main] DEBUG net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] arul@arul-win64
2015-01-28 09:48:58,204 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<authenticated>>
2015-01-28 09:48:58,274 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<authenticated>> to `true`
2015-01-28 09:48:58,274 [main] DEBUG net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
2015-01-28 09:48:58,274 [main] DEBUG net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
2015-01-28 09:48:58,283 [main] DEBUG net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
2015-01-28 09:48:58,283 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / open>>
2015-01-28 09:48:58,287 [reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=262144] >
2015-01-28 09:48:58,287 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / open>> to `SOME`
2015-01-28 09:48:58,287 [main] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request to exec `scp -f -q -p -r 'C:/Users/arul/Downloads/staging/sample.pdf'`
2015-01-28 09:48:58,287 [main] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `exec`
2015-01-28 09:48:58,288 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#0 / chanreq for exec>>
2015-01-28 09:48:58,296 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#0 / chanreq for exec>> to `SOME`
2015-01-28 09:48:58,296 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Signalling: Start status OK
2015-01-28 09:48:58,296 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 1 down to 262143
2015-01-28 09:48:58,303 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 27 down to 2097125
2015-01-28 09:48:58,303 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Read message: `T1395435423 0 1395435782 0`
2015-01-28 09:48:58,304 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Signalling: ACK: T
2015-01-28 09:48:58,304 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 1 down to 262142
2015-01-28 09:48:58,309 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 22 down to 2097103
2015-01-28 09:48:58,309 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Read message: `C0644 5600 sample.pdf`
2015-01-28 09:48:58,309 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Signalling: Remote can start transfer
2015-01-28 09:48:58,309 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 1 down to 262141
2015-01-28 09:48:58,310 [main] DEBUG net.schmizz.sshj.xfer.LoggingTransferListener - started transferring file `sample.pdf` (5600 bytes)
2015-01-28 09:48:58,313 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 1024 down to 2096079
2015-01-28 09:48:58,314 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 1024 down to 2095055
2015-01-28 09:48:58,315 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 1024 down to 2094031
2015-01-28 09:48:58,316 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 1024 down to 2093007
2015-01-28 09:48:58,317 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 1024 down to 2091983
2015-01-28 09:48:58,318 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 481 down to 2091502
2015-01-28 09:48:58,318 [main] DEBUG net.schmizz.sshj.common.StreamCopier - 5.46875 KiB transferred in 0.007 seconds (781.25 KiB/s)
2015-01-28 09:48:58,318 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Remote agrees transfer done
2015-01-28 09:48:58,319 [main] DEBUG net.schmizz.sshj.xfer.scp.SCPEngine - Signalling: Transfer done
2015-01-28 09:48:58,319 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 1 down to 262140
2015-01-28 09:49:23,422 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
2015-01-28 09:49:48,317 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
2015-01-28 09:50:13,496 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
2015-01-28 09:50:38,302 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
2015-01-28 09:51:03,569 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
2015-01-28 09:51:28,452 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
2015-01-28 09:51:53,336 [reader] DEBUG net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
Bitvise server log
<?xml version="1.0" encoding="UTF-8" ?>
<log>
<start time="2015-01-28 09:48:21.130000 -0600" appName="BvSshServer" appVersion="6.21" thisFile="C:\Program Files\Bitvise SSH Server\Logs\BvSshServer20150128-094821129-M0600.log"/>
<event seq="1" time="2015-01-28 09:48:21.129041 -0600" app="BvSshServer 6.21" name="I_SERVICE_CONFIG_DESCRIPTION" desc="Configuration description.">
<keypair algorithm="DSA" size="1024" md5="70:65:a0:c6:b0:fd:6b:46:2b:b4:e9:d6:c3:3c:a8:54" babble="xiped-vogil-defuf-toteh-gohas-lolyh-fupec-hofud-divoh-cidit-muxox"/>
<settings
wcfg="SetDefaults
server.windowsFirewall.sshPortsFirewallSetting globalScope
server.windowsFirewall.forwardedPortsFirewallSetting globalScope
With access {
With winAccounts {
Clear
With New {
winAccount "arul"
specifyGroup true
loginAllowed yes
permitTerminalShell yes
permitExecRequests yes
permitScp yes
permitSftp yes
With sfsMap {
inheritMountPoints false
With mountPoints {
Clear
CreateNewWithId 1
NewCommit
}
useDefaultSfsHomeDir false
}
permitC2SForwarding yes
permitS2CForwarding yes
}
NewCommit
}
}
"/>
</event>
<event seq="2" time="2015-01-28 09:48:21.179830 -0600" app="BvSshServer 6.21" name="I_SERVICE_SOCKET_BOUND" desc="Listening socket bound.">
<parameters listenAddress="0.0.0.0:22"/>
</event>
<event seq="3" time="2015-01-28 09:48:21.175911 -0600" app="BvSshServer 6.21" name="I_FIREWALL_EXCEPTION_ADDED" desc="Windows Firewall exception added.">
<parameters port="22" scope="Global"/>
</event>
<event seq="4" time="2015-01-28 09:48:21.176401 -0600" app="BvSshServer 6.21" name="I_SERVICE_SOCKET_BOUND" desc="Listening socket bound.">
<parameters listenAddress="[::]:22"/>
</event>
<event seq="5" time="2015-01-28 09:48:21.197283 -0600" app="BvSshServer 6.21" name="I_FIREWALL_EXCEPTION_ADDED" desc="Windows Firewall exception added.">
<parameters port="22" scope="Global"/>
</event>
<event seq="6" time="2015-01-28 09:48:21.197598 -0600" app="BvSshServer 6.21" name="I_SERVICE_CONF_SYNC_SETTINGS_DESCRIPTION" desc="Description of synchronization settings.">
<settings
wcfg="siteType standalone
"/>
</event>
<event seq="7" time="2015-01-28 09:48:21.197634 -0600" app="BvSshServer 6.21" name="I_SERVICE_CONF_SYNC_SETTINGS_APPLIED" desc="Synchronization settings successfully applied."/>
<event seq="8" time="2015-01-28 09:48:21.198179 -0600" app="BvSshServer 6.21" name="I_SERVICE_STARTED" desc="Service started.">
<parameters serviceAccount="NT AUTHORITY\SYSTEM" sessionId="0" exePath="C:\Program Files\Bitvise SSH Server\BvSshServer.exe" computerName="ARUL-WIN64" computerDomainName="" windowsVersion="6.1" servicePack="1" isDomainController="false"/>
</event>
<event seq="9" time="2015-01-28 09:48:57.613612 -0600" app="BvSshServer 6.21" name="I_CONNECT_ACCEPTED" desc="Connection accepted.">
<session id="1001" remoteAddress="192.168.29.133:50100"/>
<parameters addressRule="AnyIP" listenAddress="192.168.29.125:22"/>
</event>
<event seq="10" time="2015-01-28 09:48:57.624235 -0600" app="BvSshServer 6.21" name="I_CONNECT_VERSION_RECEIVED" desc="Client version string received.">
<session id="1001" remoteAddress="192.168.29.133:50100"/>
<parameters clientVersion="SSH-2.0-SSHJ_0_9_2"/>
</event>
<event seq="11" time="2015-01-28 09:48:57.957351 -0600" app="BvSshServer 6.21" name="I_SESSION_KEY_EXCHANGE_ALGORITHMS" desc="Key exchange algorithms.">
<session id="1001" remoteAddress="192.168.29.133:50100"/>
<parameters kexAlg="diffie-hellman-group14-sha1" cipherAlgIn="aes128-ctr" cipherAlgOut="aes128-ctr" macAlgIn="hmac-sha1" macAlgOut="hmac-sha1" comprAlgIn="none" comprAlgOut="none"/>
</event>
<event seq="12" time="2015-01-28 09:48:58.300301 -0600" app="BvSshServer 6.21" name="I_LOGON_AUTH_SUCCEEDED" desc="User authentication succeeded.">
<session id="1001" remoteAddress="192.168.29.133:50100" windowsAccount="arul-win64\arul"/>
<authentication attemptNr="1" userName="arul" method="password"/>
</event>
<event seq="13" time="2015-01-28 09:48:58.313188 -0600" app="BvSshServer 6.21" name="I_CHANNEL_SESSION_OPENED" desc="Session channel opened.">
<session id="1001" remoteAddress="192.168.29.133:50100" windowsAccount="arul-win64\arul"/>
<channel type="session" id="1"/>
</event>
<event seq="14" time="2015-01-28 09:48:58.329840 -0600" app="BvSshServer 6.21" name="I_SCP_SERVER_COMMAND_STARTED" desc="SCP command started.">
<session id="1001" remoteAddress="192.168.29.133:50100" windowsAccount="arul-win64\arul"/>
<channel type="session" id="1"/>
<parameters command="scp -f -q -p -r 'C:/Users/arul/Downloads/staging/sample.pdf'"/>
</event>
<event seq="15" time="2015-01-28 09:48:58.330421 -0600" app="BvSshServer 6.21" name="I_SFS_GET_FILE_STATUS" desc="Virtual filesystem: get file status.">
<session id="1001" remoteAddress="192.168.29.133:50100" windowsAccount="arul-win64\arul"/>
<channel type="session" id="1"/>
<sfs moduleName="FlowSfsWin" mountPath="/" code="24000" desc="Getting file status succeeded.">
<parameters path="C:\Users\arul\Downloads\staging\sample.pdf" flags="0x28" partialFailure="false"/>
</sfs>
</event>
<event seq="16" time="2015-01-28 09:48:58.330693 -0600" app="BvSshServer 6.21" name="I_SFS_GET_FILE_STATUS" desc="Virtual filesystem: get file status.">
<session id="1001" remoteAddress="192.168.29.133:50100" windowsAccount="arul-win64\arul"/>
<channel type="session" id="1"/>
<sfs moduleName="FlowSfsWin" mountPath="/" code="24000" desc="Getting file status succeeded.">
<parameters path="C:\Users\arul\Downloads\staging\sample.pdf" how="ByHandle" flags="0x29" partialFailure="false"/>
</sfs>
</event>
<event seq="17" time="2015-01-28 09:48:58.339423 -0600" app="BvSshServer 6.21" name="I_SFS_TRANSFER_FILE" desc="Virtual filesystem: transfer file.">
<session id="1001" remoteAddress="192.168.29.133:50100" windowsAccount="arul-win64\arul"/>
<channel type="session" id="1"/>
<sfs moduleName="FlowSfsWin" mountPath="/" code="90000" desc="Transferring file completed.">
<parameters path="C:\Users\arul\Downloads\staging\sample.pdf" timeMs="15" bytesRead="5600" bytesWritten="0" readRangeOffset="0" readRangeLength="5600" writeRangeOffset="0" writeRangeLength="0"/>
</sfs>
</event>
</log>
Attaching thread dump of the running JVM.
2015-01-28 09:57:31
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.71-b01 mixed mode):
"reader" prio=5 tid=0x00007fc93281c000 nid=0x5c07 runnable [0x000000013e990000]
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)
"Monitor Ctrl-Break" daemon prio=5 tid=0x00007fc93100e000 nid=0x5503 runnable [0x000000013e128000]
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 sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
- locked <0x00000006ab4c9008> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
- locked <0x00000006ab4c9008> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at com.intellij.rt.execution.application.AppMain$1.run(AppMain.java:88)
at java.lang.Thread.run(Thread.java:745)
"Service Thread" daemon prio=5 tid=0x00007fc93100d000 nid=0x5103 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread1" daemon prio=5 tid=0x00007fc933802000 nid=0x4f03 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" daemon prio=5 tid=0x00007fc933800800 nid=0x4d03 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" daemon prio=5 tid=0x00007fc93400d800 nid=0x4017 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" daemon prio=5 tid=0x00007fc932002800 nid=0x3903 in Object.wait() [0x000000013c093000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000006aaa847f8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
- locked <0x00000006aaa847f8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
"Reference Handler" daemon prio=5 tid=0x00007fc931845800 nid=0x3703 in Object.wait() [0x000000013bf90000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000006aaa84410> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
- locked <0x00000006aaa84410> (a java.lang.ref.Reference$Lock)
"main" prio=5 tid=0x00007fc932801000 nid=0x1303 in Object.wait() [0x000000011035f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000006b0633638> (a net.schmizz.sshj.common.Buffer$PlainBuffer)
at java.lang.Object.wait(Object.java:503)
at net.schmizz.sshj.connection.channel.ChannelInputStream.read(ChannelInputStream.java:107)
- locked <0x00000006b0633638> (a net.schmizz.sshj.common.Buffer$PlainBuffer)
at net.schmizz.sshj.connection.channel.ChannelInputStream.read(ChannelInputStream.java:90)
- locked <0x00000006b0633620> (a [B)
at net.schmizz.sshj.xfer.scp.SCPEngine.readMessage(SCPEngine.java:136)
at net.schmizz.sshj.xfer.scp.SCPDownloadClient.startCopy(SCPDownloadClient.java:76)
at net.schmizz.sshj.xfer.scp.SCPDownloadClient.copy(SCPDownloadClient.java:46)
- locked <0x00000006b05ba498> (a net.schmizz.sshj.xfer.scp.SCPDownloadClient)
at net.schmizz.sshj.xfer.scp.SCPFileTransfer.download(SCPFileTransfer.java:64)
at SCPDownload.main(SCPDownload.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
"VM Thread" prio=5 tid=0x00007fc931842800 nid=0x3503 runnable
"GC task thread#0 (ParallelGC)" prio=5 tid=0x00007fc932814800 nid=0x2103 runnable
"GC task thread#1 (ParallelGC)" prio=5 tid=0x00007fc931801800 nid=0x2303 runnable
"GC task thread#2 (ParallelGC)" prio=5 tid=0x00007fc931802000 nid=0x2503 runnable
"GC task thread#3 (ParallelGC)" prio=5 tid=0x00007fc931803000 nid=0x2703 runnable
"GC task thread#4 (ParallelGC)" prio=5 tid=0x00007fc931803800 nid=0x2903 runnable
"GC task thread#5 (ParallelGC)" prio=5 tid=0x00007fc931804000 nid=0x2b03 runnable
"GC task thread#6 (ParallelGC)" prio=5 tid=0x00007fc931804800 nid=0x2d03 runnable
"GC task thread#7 (ParallelGC)" prio=5 tid=0x00007fc931805800 nid=0x2f03 runnable
"GC task thread#8 (ParallelGC)" prio=5 tid=0x00007fc931806000 nid=0x3103 runnable
"GC task thread#9 (ParallelGC)" prio=5 tid=0x00007fc931806800 nid=0x3303 runnable
"VM Periodic Task Thread" prio=5 tid=0x00007fc93100b000 nid=0x5303 waiting on condition
JNI global references: 141
Heap
PSYoungGen total 306176K, used 100534K [0x00000006aaa80000, 0x00000006c0000000, 0x0000000800000000)
eden space 262656K, 38% used [0x00000006aaa80000,0x00000006b0cad840,0x00000006bab00000)
from space 43520K, 0% used [0x00000006bd580000,0x00000006bd580000,0x00000006c0000000)
to space 43520K, 0% used [0x00000006bab00000,0x00000006bab00000,0x00000006bd580000)
ParOldGen total 698880K, used 0K [0x0000000400000000, 0x000000042aa80000, 0x00000006aaa80000)
object space 698880K, 0% used [0x0000000400000000,0x0000000400000000,0x000000042aa80000)
PSPermGen total 21504K, used 8475K [0x00000003fae00000, 0x00000003fc300000, 0x0000000400000000)
object space 21504K, 39% used [0x00000003fae00000,0x00000003fb646de0,0x00000003fc300000)
This looks like an issue with Bitvise server(https://fogbugz.bitvise.com/default.asp?20514_76vcaaui). Closing this issue.
Hello @aruld I have same problem then use and don't have remote file
try (SFTPClient sftp = ssh.newSFTPClient()) {
sftp.get(filePath, tempDirectory);
}
logs
10:51:56.043 [main] DEBUG net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#1)
10:51:56.044 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#1 / open>>
10:51:56.068 [reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=1, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=0] >
10:51:56.068 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#1 / open>> to `SOME`
10:51:56.068 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request `sftp` subsystem
10:51:56.068 [main] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `subsystem`
10:51:56.068 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#1 / chanreq for subsystem>>
10:51:56.069 [reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Received window adjustment for 2097152 bytes
10:51:56.069 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Increasing by 2097152 up to 2097152
10:51:56.069 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#1 / chanreq for subsystem>> to `SOME`
10:51:56.071 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 9 down to 2097143
10:51:56.072 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 128 down to 2097024
10:51:56.073 [main] DEBUG net.schmizz.sshj.sftp.SFTPEngine - Server version 3
10:51:56.077 [main] DEBUG net.schmizz.sshj.sftp.SFTPEngine - Sending Request{1;STAT}
10:51:56.077 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 18 down to 2097125
10:51:56.077 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<sftp / 1>>
10:51:56.078 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 41 down to 2096983
10:51:56.078 [sftp reader] DEBUG net.schmizz.sshj.sftp.PacketReader - Received ATTRS packet
10:51:56.079 [sftp reader] DEBUG net.schmizz.concurrent.Promise - Setting <<sftp / 1>> to `Buffer [rpos=5, wpos=37, size=37]`
10:51:56.084 [main] DEBUG net.schmizz.sshj.xfer.LoggingTransferListener - started transferring file `1.txt` (85 bytes)
10:51:56.085 [main] DEBUG net.schmizz.sshj.sftp.SFTPEngine - Sending Request{2;OPEN}
10:51:56.085 [main] DEBUG net.schmizz.sshj.connection.channel.Window$Remote - Consuming by 27 down to 2097098
10:51:56.085 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<sftp / 2>>
10:51:56.086 [reader] DEBUG net.schmizz.sshj.connection.channel.Window$Local - Consuming by 33 down to 2096950
10:51:56.086 [sftp reader] DEBUG net.schmizz.sshj.sftp.PacketReader - Received STATUS packet
10:51:56.086 [sftp reader] DEBUG net.schmizz.concurrent.Promise - Setting <<sftp / 2>> to `Buffer [rpos=5, wpos=29, size=29]`
10:51:56.092 [main] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending close
10:51:56.093 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<chan#1 / close>>
10:51:56.094 [reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Got chan request for `exit-status`
10:51:56.094 [reader] DEBUG net.schmizz.sshj.connection.channel.direct.SessionChannel - Got close
10:51:56.094 [reader] DEBUG net.schmizz.sshj.connection.ConnectionImpl - Forgetting `session` channel (#1)
10:51:56.094 [reader] DEBUG net.schmizz.concurrent.Promise - Setting <<chan#1 / close>> to `SOME`
Exception in thread "main" net.schmizz.sshj.sftp.SFTPException: No such file
at net.schmizz.sshj.sftp.Response.error(Response.java:113)
at net.schmizz.sshj.sftp.Response.ensurePacketTypeIs(Response.java:91)
at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:135)
at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:143)
at net.schmizz.sshj.sftp.SFTPEngine.open(SFTPEngine.java:148)
at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.downloadFile(SFTPFileTransfer.java:142)
at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.download(SFTPFileTransfer.java:112)
at net.schmizz.sshj.sftp.SFTPFileTransfer$Downloader.access$300(SFTPFileTransfer.java:97)
at net.schmizz.sshj.sftp.SFTPFileTransfer.download(SFTPFileTransfer.java:78)
at net.schmizz.sshj.sftp.SFTPFileTransfer.download(SFTPFileTransfer.java:64)
at net.schmizz.sshj.sftp.SFTPClient.get(SFTPClient.java:233)
at ru.bellintegrator.globus.listener.SshCommand.getFromRemoteHost(SshCommand.java:140)
at ru.bellintegrator.globus.listener.SshCommand.main(SshCommand.java:79)
in dumps have don't closed thread
"reader" #13 prio=5 os_prio=0 tid=0x000000001a5e3000 nid=0x1740 runnable [0x000000001b71e000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at net.schmizz.sshj.transport.Reader.run(Reader.java:50)
Hi @BioQwer,
I don't quite understand what you're saying. Which SSH server are you using, and what do you mean with don't have remote file?
Hello @hierynomus
I connect from Windows 8 to Debian with (OpenSSH_6.0p1 Debian-4+deb7u2, OpenSSL 1.0.1e 11 Feb 2013)
In variable filePath i put not valid path to file, try download to sys temp directory.
In thread main i get Exception SFTPException: No such file, but thread reader don't close.
Actually the reader is always active until you actually close the client I think, have you tried that?
public class SshCommand implements Closeable {
private static final Logger LOGGER = LogManager.getLogger(SshCommand.class);
private String _host;
private String _login;
private String _password;
private SSHClient ssh = new SSHClient();
/**
* Create object for ssh session by credentials.
*
* @param host host
* @param login login
* @param password password
*/
public SshCommand(String host, String login, String password) {
this._host = host;
this._login = login;
this._password = password;
}
/**
* Create object for ssh session by credentials without password.
*
* @param host host
* @param login login
*/
public SshCommand(String host, String login) {
this._host = host;
this._login = login;
}
/**
* Connect to remote server.
*
* @throws NotConnectedException
*/
public void connect() throws NotConnectedException, IOException {
try {
System.setProperty("file.encoding", "UTF-8");
Field charset = Charset.class.getDeclaredField("defaultCharset");
charset.setAccessible(true);
charset.set(null, null);
} catch (IllegalAccessException | NoSuchFieldException e) {
e.getMessage();
}
try {
if (_password != null) {
ssh.addHostKeyVerifier(new PromiscuousVerifier());
} else {
ssh.loadKnownHosts();
}
ssh.connect(_host);
if (_password != null) {
ssh.authPassword(_login, _password);
} else {
ssh.authPublickey(System.getProperty("user.name"));
}
} catch (TransportException te) {
throw new NotConnectedException(te.getMessage(), te.getCause());
}
LOGGER.info("Connected to {}@{}", _login, _host);
}
/**
* Execute shell command on remote server.<br> Before execute necessary to
* connect.
*
* @param shellCommand shell command
* @return InputStream with output of execution.
* @throws Exception
*/
public InputStream executeShellCommand(String shellCommand) throws
Exception {
Session.Command cmd = null;
Session session = ssh.startSession();
cmd = session.exec(shellCommand);
LOGGER.info("{}@{}:# {}", _login, _host, shellCommand);
return cmd.getInputStream();
}
public void getFromRemoteHost(String filePath, String tempDirectory) throws
ExecutionException, IOException {
try (SFTPClient sftp = ssh.newSFTPClient()) {
sftp.get(filePath, tempDirectory);
}
}
@Override
public void close() throws IOException {
ssh.close();
}
//TODO удалить
public static void main(String[] args) throws Throwable {
LOGGER.info("Start!");
String host = "hadoop08";
String login = "root";
String password = "123QWErty";
//password = null;
SshCommand script = new SshCommand(host, login, password);
script.connect();
List<String> res = null;
try (InputStream ioResult = script.executeShellCommand("ls -lh")) {
res = IOUtils.readLines(ioResult);
}
for (String line : res) {
System.out.println(line);
}
script.close();
script.connect();
script.getFromRemoteHost("1.txt", FileUtils.getTempDirectory()
.getAbsolutePath());
script.close();
}
}
if use
script.close();
script.connect();
for this i have
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:705)
at net.schmizz.sshj.transport.TransportImpl.init(TransportImpl.java:174)
at net.schmizz.sshj.SSHClient.onConnect(SSHClient.java:722)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:54)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:80)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:115)
at ru.bellintegrator.globus.listener.SshCommand.connect(SshCommand.java:80)
at ru.bellintegrator.globus.listener.SshCommand.main(SshCommand.java:146)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
if run only
script.connect();
script.getFromRemoteHost("1.txt", FileUtils.getTempDirectory()
.getAbsolutePath());
script.close();
reader the same way don't close
Yes, but doesn't the script.getFromRemoteHost(...) throw the exception?
have you tried:
script.connect();
try {
script.getFromRemoteHost("1.txt", FileUtils.getTempDirectory().getAbsolutePath());
} finally {
script.close();
}
Thank you very much for your help! All great works. It is necessary to properly close.
try (SshCommand script = new SshCommand(host, login, password)) {
script.connect();
List<String> res = null;
try (InputStream ioResult = script.executeShellCommand("ls -lh")) {
res = IOUtils.readLines(ioResult);
}
for (String line : res) {
System.out.println(line);
}
script.getFromRemoteHost("1.txt", FileUtils.getTempDirectory()
.getAbsolutePath());
}