GithubHelp home page GithubHelp logo

hierynomus / sshj Goto Github PK

View Code? Open in Web Editor NEW
2.4K 124.0 588.0 8.6 MB

ssh, scp and sftp for java

License: Apache License 2.0

Java 95.44% Groovy 4.28% Shell 0.29%
java ssh ssh-client sftp sftp-client scp

sshj's People

Contributors

adagios avatar aiwaniuk avatar andremoniy avatar bluekeyes avatar boris-de avatar dkocher avatar eidottermihi avatar exceptionfactory avatar fabianhenneke avatar fingolfin avatar hierynomus avatar hpoettker avatar iocanel avatar jpstotz avatar kegelh avatar lguerin avatar liff avatar matenhagen avatar matthew-dailey avatar maxd avatar meteorite avatar moritz31 avatar neilprosser avatar oliviersalasc avatar rasantel avatar romainreuillon avatar shikhar avatar trancelove avatar vladimirlagunov avatar wyrzyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sshj's Issues

OpenSSH public key not working

This works on my dev box but not on our server.

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

Here's the output:

   [junit] Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
    [junit] Client identity string: SSH-2.0-SSHJ_0_6_0
    [junit] Server identity string: SSH-2.0-OpenSSH_4.3
    [junit] Setting <<kex done>> to `null`
    [junit] Sending SSH_MSG_KEXINIT
    [junit] Setting <<kexinit sent>> to `SOME`
    [junit] Awaiting <<kex done>>
    [junit] Received SSH_MSG_KEXINIT
    [junit] Negotiated algorithms: [ kex=diffie-hellman-group1-sha1; sig=ssh-rsa; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
    [junit] Sending SSH_MSG_KEXDH_INIT
    [junit] Received kex followup data
    [junit] Received SSH_MSG_KEXDH_REPLY
    [junit] Trying to verify host key with net.schmizz.sshj.transport.verification.OpenSSHKnownHosts@5e9de959
    [junit] Sending SSH_MSG_NEWKEYS
    [junit] Received SSH_MSG_NEWKEYS
    [junit] Setting <<kexinit sent>> to `null`
    [junit] Setting <<kex done>> to `SOME`
    [junit] Key exchange took 0.107 seconds
    [junit] Attempting to load key from: /var/go/.ssh/id_rsa
    [junit] Could not load keys due to: {}
    [junit] net.schmizz.sshj.common.SSHException: No provider available for OpenSSH key file
    [junit]     at net.schmizz.sshj.SSHClient.loadKeys(SSHClient.java:482)
    [junit]     at net.schmizz.sshj.SSHClient.loadKeys(SSHClient.java:438)
    [junit]     at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:348)
    [junit]     at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:282)
    [junit]     at com.tws.util.SSH.exec(SSH.java:29)
    [junit]     at com.tws.cloud.ReverseProxyTest.cleanUpProxyRules(ReverseProxyTest.java:44)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:597)
    [junit]     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    [junit]     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    [junit]     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    [junit]     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:37)
    [junit]     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    [junit]     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
    [junit]     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
    [junit]     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    [junit]     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    [junit]     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    [junit]     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    [junit]     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    [junit]     at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
    [junit]     at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:420)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1339)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:831)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785)
    [junit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [junit]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:597)
    [junit]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [junit]     at org.apache.tools.ant.Target.execute(Target.java:357)
    [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
    [junit]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    [junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    [junit]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    [junit]     at org.apache.tools.ant.Main.runBuild(Main.java:758)
    [junit]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
    [junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    [junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

EOF when trying to read/write file using Tectia SSH Server

We're having issues communicating with Tectia's SSH server using the latest SSHJ client (0.7.0). Here's the test code and a dump of the error log:

import java.io.InputStream;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.SFTPEngine;
import net.schmizz.sshj.sftp.StatefulSFTPClient;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;

import org.apache.commons.io.IOUtils;

public class SFTPTest {
  public static void main(String[] args)
      throws Exception {
    SSHClient client = new SSHClient();
    client.addHostKeyVerifier(new PromiscuousVerifier());
    client.connect("127.0.0.1", 22);
    client.authPassword("test", "test");

    StatefulSFTPClient sftp = new StatefulSFTPClient(new SFTPEngine(client).init());
    System.out.println("File Exists: " + sftp.statExistence("test.txt"));

    InputStream input = sftp.open("test.txt").getInputStream();
    IOUtils.copy(input, System.out);
    IOUtils.closeQuietly(input);

    sftp.close();
    client.close();
  }
}

stdout:

File Exists: [size=14;mode=[mask=100600];atime=1326843624,mtime=1326843624;]

stderr:

317 [main] INFO net.schmizz.sshj.common.SecurityUtils - Trying to register BouncyCastle as a JCE provider
800 [main] INFO net.schmizz.sshj.common.SecurityUtils - Registration succeeded
853 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_7
856 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-6.2.3.168 SSH Tectia Server
857 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
5348 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
5395 [reader] INFO net.schmizz.sshj.transport.kex.DHG14 - Sending SSH_MSG_KEXDH_INIT
5536 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
5537 [reader] INFO net.schmizz.sshj.transport.kex.DHG14 - Received SSH_MSG_KEXDH_REPLY
5582 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
5582 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
5586 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 4.729 seconds
5588 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5707 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5707 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
5708 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
5708 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] [email protected]
5725 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5819 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5819 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
5819 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
5835 [main] INFO net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
5836 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5840 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=65536] >
5840 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request `sftp` subsystem
5840 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `subsystem`
5919 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5929 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5929 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5929 [main] INFO net.schmizz.sshj.sftp.SFTPEngine - Server version 3
5935 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5935 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5937 [main] INFO net.schmizz.sshj.sftp.StatefulSFTPClient - Start dir = /C:/Documents and Settings/test
5939 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5941 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5962 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5963 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5973 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5973 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got chan request for `exit-status`
5973 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5973 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got EOF
5973 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
5992 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got close
5992 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending EOF
5993 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending close
5993 [reader] INFO net.schmizz.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
5996 [main] ERROR net.schmizz.concurrent.Promise - <<sftp / 4>> woke to: net.schmizz.sshj.sftp.SFTPException: EOF while reading packet
Exception in thread "main" net.schmizz.sshj.sftp.SFTPException: EOF while reading packet
  at net.schmizz.sshj.sftp.PacketReader.readIntoBuffer(PacketReader.java:52)
  at net.schmizz.sshj.sftp.PacketReader.getPacketLength(PacketReader.java:57)
  at net.schmizz.sshj.sftp.PacketReader.readPacket(PacketReader.java:67)
  at net.schmizz.sshj.sftp.PacketReader.run(PacketReader.java:84)

You can grab the server here - http://www.tectia.com/en/Customers/Evaluate/Client_-_Server.iw3. I have only tested the Windows server (on XP). Setup is relatively straight forward, everything is set up straight out of the box, all you need to do is create a user named test with the password test and drop a file called "test.txt" into their home directory.

Let me know if you need any more info.

Protocol Error - Channel Failure on ExtremeXOS based devices.

Version 0.6.1

Trying to execute a command in: BlackDiamond8810, Summit48I and SummitX480 (Extreme Networks) and all of them cause this error on log.

14 [main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider
516 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
608 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_6_0
635 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-4.1.2 SSH Secure Shell Toolkit
635 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
656 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
708 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT
842 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
844 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY
875 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
875 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
881 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 0.246 seconds
910 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
911 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
911 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] [email protected]
1059 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
1059 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
1067 [main] INFO net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
1087 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=16384] >
1088 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request to exec `show lacp counters`
1088 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `exec`
1107 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Received SSH_MSG_IGNORE
1107 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got EOF
1108 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Got close
1108 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending EOF
1108 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending close
1108 [reader] INFO net.schmizz.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
1125 [reader] ERROR net.schmizz.sshj.transport.TransportImpl - Dying because - net.schmizz.sshj.connection.ConnectionException: [PROTOCOL_ERROR] Received CHANNEL_FAILURE on unknown channel #0
1126 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to null-service

the code:

final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect("192.168.10.5");
try {
    ssh.authPassword("user", "pass");
    final Session session = ssh.startSession();
    try {
        final Command cmd = session.exec("show lacp counters");
        cmd.join(5, TimeUnit.SECONDS);
        System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
        System.out.println("\nEXIT STATUS: " + cmd.getExitStatus());
    } finally {
        session.close();
    }
} finally {
    ssh.disconnect();
}

In another devices, like Cisco or Juniper, this code works properly.

Thanks,
Elias

SCPFileTransfer doesn't support wildcard in file path?

version 0.6.1

This code works fine:
ssh.newSCPFileTransfer().download("/home/test.ini", "C:/test");

But this doesn't work:
ssh.newSCPFileTransfer().download("/home/*.ini", "C:/test");

Got error message:

02:22:31.190 [main] INFO  n.s.s.c.c.direct.SessionChannel - Will request to exec `scp -f -q -p -r '/home/*.ini'`
.......
Caused by: net.schmizz.sshj.xfer.scp.SCPException: Remote SCP command returned error: scp: /home/*.ini: No such file or directory

Mkdir permission denied

Pretty sure this is not a bug, but since I receive a permission denied when creating a remote dir, whilst it is possible to
create the directory in WinSCP I thought I should post it there. Is there something I've missed out in the initialisation?

SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier("somehostkeyverifier");
ssh.loadKnownHosts();
ssh.connect(FTP_ADDRESS);
ssh.authPassword(FTP_USER, FTP_PWD);

SFTPClient sftp = ssh.newSFTPClient(); 
sftp.mkdir(FTP_REMOTE_DIR);
net.schmizz.sshj.sftp.SFTPException: Permission denied
        at net.schmizz.sshj.sftp.Response.error(Response.java:113)
        at net.schmizz.sshj.sftp.Response.ensureStatusIs(Response.java:106)
        at net.schmizz.sshj.sftp.Response.ensureStatusPacketIsOK(Response.java:99)
        at net.schmizz.sshj.sftp.SFTPEngine.makeDir(SFTPEngine.java:166)
        at net.schmizz.sshj.sftp.SFTPEngine.makeDir(SFTPEngine.java:171)
        at net.schmizz.sshj.sftp.SFTPClient.mkdir(SFTPClient.java:87)

DEBUG level on net.schmizz

2012-02-08 10:24:02 Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
2012-02-08 10:24:02 Client identity string: SSH-2.0-SSHJ_0_8
2012-02-08 10:24:02 Server identity string: SSH-2.0-mod_sftp/0.9.7
2012-02-08 10:24:02 Setting <<kex done>> to `null`
2012-02-08 10:24:02 Sending SSH_MSG_KEXINIT
2012-02-08 10:24:02 Received SSH_MSG_KEXINIT
2012-02-08 10:24:02 Setting <<kexinit sent>> to `SOME`
2012-02-08 10:24:02 Awaiting <<kex done>>
2012-02-08 10:24:02 Negotiated algorithms: [ kex=diffie-hellman-group14-sha1; sig=ssh-rsa; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
2012-02-08 10:24:02 Sending SSH_MSG_KEXDH_INIT
2012-02-08 10:24:02 Received kex followup data
2012-02-08 10:24:02 Received SSH_MSG_KEXDH_REPLY
2012-02-08 10:24:02 Trying to verify host key with net.schmizz.sshj.SSHClient$1@3429ace1
2012-02-08 10:24:02 Sending SSH_MSG_NEWKEYS
2012-02-08 10:24:02 Received SSH_MSG_NEWKEYS
2012-02-08 10:24:02 Setting <<kexinit sent>> to `null`
2012-02-08 10:24:02 Setting <<kex done>> to `SOME`
2012-02-08 10:24:02 Key exchange took 0.284 seconds
2012-02-08 10:24:04 Setting <<service accept>> to `null`
2012-02-08 10:24:04 Sending SSH_MSG_SERVICE_REQUEST for ssh-userauth
2012-02-08 10:24:04 Awaiting <<service accept>>
2012-02-08 10:24:04 Setting <<service accept>> to `SOME`
2012-02-08 10:24:04 Setting active service to ssh-userauth
2012-02-08 10:24:04 Trying `password` auth...
2012-02-08 10:24:04 Setting <<authenticated>> to `null`
2012-02-08 10:24:04 Requesting password for [AccountResource] theserver@someserveeeer
2012-02-08 10:24:04 Awaiting <<authenticated>>
2012-02-08 10:24:04 Setting <<authenticated>> to `SOME`
2012-02-08 10:24:04 `password` auth successful
2012-02-08 10:24:04 Setting active service to ssh-connection
2012-02-08 10:24:05 Attaching `session` channel (#0)
2012-02-08 10:24:05 Awaiting <<chan#0 / open>>
2012-02-08 10:24:05 Initialized - < session channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=4294967295] >
2012-02-08 10:24:05 Setting <<chan#0 / open>> to `SOME`
2012-02-08 10:24:05 Will request `sftp` subsystem
2012-02-08 10:24:05 Sending channel request for `subsystem`
2012-02-08 10:24:05 Awaiting <<chan#0 / chanreq for subsystem>>
2012-02-08 10:24:05 Setting <<chan#0 / chanreq for subsystem>> to `SOME`
2012-02-08 10:24:05 Consuming by 9 down to 4294967286
2012-02-08 10:24:05 Consuming by 124 down to 2097028
2012-02-08 10:24:05 Server version 3
2012-02-08 10:24:05 Sending Request{1;OPENDIR}
2012-02-08 10:24:05 Consuming by 14 down to 4294967272
2012-02-08 10:24:05 Awaiting <<sftp / 1>>
2012-02-08 10:24:05 Consuming by 19 down to 2097009
2012-02-08 10:24:05 Received HANDLE packet
2012-02-08 10:24:05 Setting <<sftp / 1>> to `Buffer [rpos=5, wpos=15, size=15]`
2012-02-08 10:24:05 Sending Request{2;READDIR}
2012-02-08 10:24:05 Consuming by 19 down to 4294967253
2012-02-08 10:24:05 Awaiting <<sftp / 2>>
2012-02-08 10:24:05 Consuming by 313 down to 2096696
2012-02-08 10:24:05 Received NAME packet
2012-02-08 10:24:05 Setting <<sftp / 2>> to `Buffer [rpos=5, wpos=309, size=309]`
2012-02-08 10:24:05 Sending Request{3;READDIR}
2012-02-08 10:24:05 Consuming by 19 down to 4294967234
2012-02-08 10:24:05 Awaiting <<sftp / 3>>
2012-02-08 10:24:05 Consuming by 37 down to 2096659
2012-02-08 10:24:05 Received STATUS packet
2012-02-08 10:24:05 Setting <<sftp / 3>> to `Buffer [rpos=5, wpos=33, size=33]`
2012-02-08 10:24:05 Closing `RemoteResource{.}`
2012-02-08 10:24:05 Sending Request{4;CLOSE}
2012-02-08 10:24:05 Consuming by 19 down to 4294967215
2012-02-08 10:24:05 Awaiting <<sftp / 4>>
2012-02-08 10:24:05 Consuming by 28 down to 2096631
2012-02-08 10:24:05 Received STATUS packet
2012-02-08 10:24:05 Setting <<sftp / 4>> to `Buffer [rpos=5, wpos=24, size=24]`
2012-02-08 10:24:05 Sending Request{5;OPENDIR}
2012-02-08 10:24:05 Consuming by 14 down to 4294967201
2012-02-08 10:24:05 Awaiting <<sftp / 5>>
2012-02-08 10:24:05 Consuming by 19 down to 2096612
2012-02-08 10:24:05 Received HANDLE packet
2012-02-08 10:24:05 Setting <<sftp / 5>> to `Buffer [rpos=5, wpos=15, size=15]`
2012-02-08 10:24:05 Sending Request{6;READDIR}
2012-02-08 10:24:05 Consuming by 19 down to 4294967182
2012-02-08 10:24:05 Awaiting <<sftp / 6>>
2012-02-08 10:24:06 Consuming by 313 down to 2096299
2012-02-08 10:24:06 Received NAME packet
2012-02-08 10:24:06 Setting <<sftp / 6>> to `Buffer [rpos=5, wpos=309, size=309]`
2012-02-08 10:24:06 Sending Request{7;READDIR}
2012-02-08 10:24:06 Consuming by 19 down to 4294967163
2012-02-08 10:24:06 Awaiting <<sftp / 7>>
2012-02-08 10:24:06 Consuming by 37 down to 2096262
2012-02-08 10:24:06 Received STATUS packet
2012-02-08 10:24:06 Setting <<sftp / 7>> to `Buffer [rpos=5, wpos=33, size=33]`
2012-02-08 10:24:06 Closing `RemoteResource{.}`
2012-02-08 10:24:06 Sending Request{8;CLOSE}
2012-02-08 10:24:06 Consuming by 19 down to 4294967144
2012-02-08 10:24:06 Awaiting <<sftp / 8>>
2012-02-08 10:24:06 Consuming by 28 down to 2096234
2012-02-08 10:24:06 Received STATUS packet
2012-02-08 10:24:06 Setting <<sftp / 8>> to `Buffer [rpos=5, wpos=24, size=24]`
2012-02-08 10:24:16 Sending Request{9;MKDIR}
2012-02-08 10:24:16 Consuming by 21 down to 4294967123
2012-02-08 10:24:16 Awaiting <<sftp / 9>>
2012-02-08 10:24:16 Consuming by 43 down to 2096191
2012-02-08 10:24:16 Received STATUS packet
2012-02-08 10:24:16 Setting <<sftp / 9>> to `Buffer [rpos=5, wpos=39, size=39]`
2012-02-08 10:25:40 Dying because - net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Default disconnect listener - UNKNOWN
2012-02-08 10:25:40 Got notified of net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Notified of net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Channel #0 got notified of net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
2012-02-08 10:25:40 Forgetting `session` channel (#0)
2012-02-08 10:25:40 Setting <<chan#0 / close>> to `SOME`
2012-02-08 10:25:40 Setting active service to null-service
2012-02-08 10:25:40 Setting <<transport close>> to `SOME`
2012-02-08 10:25:40 Stopping

Race condition in AbstractChannel channel requests (0.6.0 regression)

I use quartz concurrent execute multi trigger, sometime has happen below error

[11/09/30 15:20:30][ERROR][net.schmizz.sshj.transport.TransportImpl-570] Dying because - net.schmizz.sshj.connection.ConnectionException: [PROTOCOL_ERROR] Received response to channel request when none was requested
[11/09/30 15:20:30][ERROR][net.schmizz.concurrent.Promise-171] <<chan#7 / chanreq for exec>> woke to: net.schmizz.sshj.connection.ConnectionException: [PROTOCOL_ERROR] Received response to channel request when none was requested

I open once connection , start multi session, exec command by one job

my code :

ssh = new SSHClient();
            ssh.setTimeout(sshTimeout);
            ssh.addHostKeyVerifier(  
                new HostKeyVerifier() { 
                    @Override
                    public boolean verify(String arg0, int arg1, PublicKey arg2) {  
                        return true;  // don't bother verifying  
                    }
                }  
            ); 
            ssh.connect(ip, port);
            ssh.authPassword(username, password);

public List<String> send(String command){
        String result = "";
        try {
            Session session = ssh.startSession();
            try {
                session.allocatePTY("vt100", 1024, 24, 640, 480, new EnumMap<PTYMode, Integer>(PTYMode.class));
                Command cmd = session.exec(command);
                cmd.join(cmdTimeout, TimeUnit.MILLISECONDS);
                result = IOUtils.readFully(cmd.getInputStream()).toString();
                cmd.close();
            }catch(Exception e){
                log.error(" ip : " + ip + " send '" + command + "' command error, message is : " + e);
            }finally {
                session.close();
            }
        }catch(Exception e){
            log.error(" ip : " + ip + " session close error, message is : " + e);
        }
}

Initializing SFTP raises exception

When trying to initialize a SFTP connection I get an exception.

SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier("someverifier");
ssh.loadKnownHosts();
ssh.connect(FTP_ADDRESS);
ssh.authPassword(FTP_USER, FTP_PWD);
SFTPClient sftp = ssh.newSFTPClient(); 
java.lang.RuntimeException: Invalid value: -1
        at net.schmizz.sshj.common.Buffer.putUInt32(Buffer.java:329)
        at net.schmizz.sshj.connection.channel.ChannelOutputStream$DataBuffer.flush(ChannelOutputStream.java:118)
        at net.schmizz.sshj.connection.channel.ChannelOutputStream$DataBuffer.flush(ChannelOutputStream.java:98)
        at net.schmizz.sshj.connection.channel.ChannelOutputStream.flush(ChannelOutputStream.java:209)
        at net.schmizz.sshj.sftp.SFTPEngine.transmit(SFTPEngine.java:262)
        at net.schmizz.sshj.sftp.SFTPEngine.init(SFTPEngine.java:69)
        at net.schmizz.sshj.SSHClient.newSFTPClient(SSHClient.java:623)

I am using v 0.7.0 from the maven repository.

How to put a file to sftp using private key

hi

I'm trying to upload a file to a sftp server using private key authentication. please provide one example for this. I searched for so long , I could't be able to find any help;

thanks
raghu

Maintaining State Between execs

If I do the following:

// start a shell
ssh.startSession().startShell(); 
// change to the /tmp/ directory
ssh.startSession().exec("cd /tmp/").join(); 
// print out the current directory
Command cmd = ssh.startSession().exec("pwd"); 
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join();

Shouldn't I see the current directory as /tmp/? I thought that once you start a shell, all subsequent execs would maintain state between the calls, but I am not observing this. It seems when I try to do the above, it always looks like I stay in the initial directory. Is there something I am missing, is there another way to do this, or is this an error?

sshj hangup while sending data through ChannelOutputStream

Hello.
There are several issues while sending data through sshj data_channel:

  1. When sshj connects to ssh server with small window size (smaller that maximum packet size)
    and try to sent through data_channel data, more than this window accepts, sshj hangs
    The possible explanation is sshj don't send any CHANNEL_WINDOW_ADJUST message to server and lock.wait() don't get interrupted.
  2. When sshj connect to ssh server and local windows size (2MB) is greater than remote window size (1MB) while writing data to that channel server recieved sshPacket with size(32777) more than maxPacketSize allows (32768) and ssh server exits and sshj exits
    too.
    The possible explanation to this, is that at the beggining of trans.write buffer.rpos() = 5 and buffer.wpos()=14 9 bytes that ruines sshPacket. I managed this issue by adding final int x = Math.min(len, win.getMaxPacketSize() - 9 - bufferLength). But i don`t think this is correct patch for this issue.

All tests could be done with dropbear ssh server where you could reproduce this problem
With OpenSSH everything works great
.

RE: intermittent key exchange failures

just like in the issue #18 that was closed, the issue still remains for the version 0.5.0 of sshj.

Here is the log that I obtain:

12:51:45,040 [reader] ERROR (net.schmizz.sshj.transport.TransportImpl:570) - Dying because - net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
12:51:45,047 [AsyncTask] ERROR (net.schmizz.concurrent.Promise:171) - <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
12:51:45,048 [AsyncTask] ERROR (FW:75) - class com.orange.fcr.business.impl.AsynchronousTicketHandler:An exception happend while running task DeleteAddress:InitTerminalTask
com.orange.fcr.business.TaskException: net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
    at com.orange.fcr.business.task.InitTerminalTask.run(InitTerminalTask.java:39)
    at com.orange.fcr.business.impl.BaseAbstractTicketHandler.run(BaseAbstractTicketHandler.java:37)
    at com.orange.fcr.business.impl.AsynchronousTicketHandler.executeCommand(AsynchronousTicketHandler.java:99)
    at com.orange.fcr.business.impl.AsynchronousTicketHandler.access$200(AsynchronousTicketHandler.java:24)
    at com.orange.fcr.business.impl.AsynchronousTicketHandler$AsynchronousTask$1.call(AsynchronousTicketHandler.java:119)
    at com.orange.fcr.business.impl.AsynchronousTicketHandler$AsynchronousTask$1.call(AsynchronousTicketHandler.java:117)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.lang.Thread.run(Thread.java:662)
Caused by: net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
    at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:152)
    at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:372)
    at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:477)
    at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
    at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:72)

Does anyone have an idea about it?

sftp v2 protocol support

I'm using your fine library for sftp connections, but recently I had to connect to a ancient server, that only supports protocol 2.

After checking the v3 documentation, I realized that the differences between v2 and v3 are minimal, and it's easy to add v2 support.

The following patch adds protocol v2 support. Obviuosly, this should be rewritten to check for the connection version, and only omit the status message if the connection protocol is V2, but I did not have the time to figure out how to do that. I have done some minimal testing on the code, and it works for my purposes.

diff -r shikhar-sshj-v2/src/main/java/net/schmizz/sshj/sftp/Response.java shikhar-sshj-56e135e/src/main/java/net/schmizz/sshj/sftp/Response.java
75c75
<                 throw new SFTPException(readStatusCode(), /*readString()*/ "Stoty meghekkelte hogy menjen v2-vel");

---
>                 throw new SFTPException(readStatusCode(), readString());
diff -r shikhar-sshj-v2/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java shikhar-sshj-56e135e/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java
38c38
<     public static final int PROTOCOL_VERSION = 2;

---
>     public static final int PROTOCOL_VERSION = 3;

Is SSHJ client threadsafe???

Can anyone tell me if the sshClient is threadsafe?

I am working with the version 0.5 of sshj, and I wanted to create an objectPool with the jakarta common pool api, and I need it to know if it is threadsafe?

Thanks by advance for your help

Not getting pre-login banner

Summary: Cannot get the pre-login banner from my RHEL 5 & Centos 5 servers.

Remote systems: RHEL 5 & Centos 5 systems running OpenSSH 4.3p2.
Remote sys config: Password based authentication - default RHEL 5 / CentOS 5 w/ "Banner /etc/ssh/sshd_banner.txt" config in /etc/ssh/sshd_config. The file sshd_banner.txt is a simple text file.

Description:
I am trying to get the banner multiple times during the different stages of session startup and even before teardown using
ssh.getUserAuth().getBanner() where ssh is an instance of SSHClient.

The getBanner() method always comes back as "" instead of the null that is mentioned in the documentation:
https://github.com/shikhar/sshj/blob/master/src/main/java/net/schmizz/sshj/userauth/UserAuth.java#L52

That is because it is initialized to "" here: https://github.com/shikhar/sshj/blob/master/src/main/java/net/schmizz/sshj/userauth/UserAuthImpl.java#L46

The documentation issue is a minor one at this point. I can see the banner fine with the openssh client. I tried JSch as well and the banner is available when connecting with JSch.

At this point I am not even sure, that the banner is actually sent when connecting with sshj. Before I spend more time on debugging this problem further, I want to make sure I am not missing something. Anyone else having problems with this?

Update 1
I tried connecting to an OpenBSD 5.0 system running OpenSSH 5.9. Interestingly, the pre-login banner is shown by the 5.9 server. It seems the message sequence used by sshj is tripping up the OpenSSH 4.3 server and it is not sending the banner. But why is the message sequence used by sshj different from the OpenSSH client or JSch?

Update 2
I dug deeper and I found that not seeing a pre-auth banner on OpenSSH 4.3 actually is caused by the server not sending one. Apparently in OpenSSH 4.3 the pre-auth banner is only sent if the client requests authentication method "none". The OpenSSH team fixed that issue no too long after 4.3 (http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/auth2.c#rev1.117) but the fix never made it into the RHEL 5 sources.
For test purposes I inserted a call to AuthNone in UserAuthImpl.authenticate() before the main loop through the authentication methods and the banner showed up.
There is another issue in sshj. While looking through the authenticate method, I noticed that sshj does not seem to take into account the allowed methods by the server. It should really make that call to AuthNone first, take the server accepted out of the reply and populate the allowedMethods HashSets with that instead of just populating it based on the methods passed in by the user. Using the "none" method to get the allowed methods seems to be the standard way to do this in other SSH clients but is not mandated in RFC 4252.

Multithreading sftp uploading leads to incorrect DEBUG log messages

Hi Shikhar,

I use spring scheduler (based on quartz when tasks are executed in different threads).
So each task uploads a different file but to the same host and folder.
For example:

task1 ---------------------------------------------->
taks2                      -------------------------------------------->
task3                              ------------------------------------>

So as you can see when task1 is in the middle of uploading, task2 starts to upload another file to the same host and even to the same folder. It seems that all files are transfered successfully but I get strange debug logs like the below. 182% transfered! For more information I can send you full logs. I don't see how to attach files here.

DEBUG [LoggingTransferListener] transferred 182% of `XXXXXXXX.txt`
[SFTPEngine] Sending Request{2666;WRITE}
DEBUG [Window$Remote] Consuming by 32768 down to 65536
DEBUG [Promise] Awaiting <<sftp / 2666>>

Feature-based walk throughs on wiki

javadoc is well and good but mainly you want to use a specific thing, e.g. scp, sftp, port forwarding, execute a command, ...

should setup a page/pages on the wiki walking through these use cases

Reading file contents thru RandomAccessRemoteFile is too slow

Hi,

I need to read a file's contents, changed file contents, periodically reading only the changed contents from last read. I tried to use RandomAccessRemoteFile but it was too slow. Reading an entire file thru RandomAccessRemoteFile is about 100 times slower than reading the entire file using RemoteFile. Even reading changed contents (few lines) isn't fast enough.

Is there any way to get this to work faster?

Regards,
Prakash

sshj fails password auth

I'm using sshj for file transfer to a remote server of a business partner. In our testing environment (Ubuntu 10.10) everything works fine and sshj runs smoothly. However, when we try to connect to the remote machine of our partner, sshj fails the password authentication.

011-06-16 00:04:49,844 WARN  [net.schmizz.sshj.DefaultConfig] (ajp-127.0.0.1-8009-16) Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
2011-06-16 00:04:49,865 INFO  [net.schmizz.sshj.transport.TransportImpl] (ajp-127.0.0.1-8009-16) Client identity string: SSH-2.0-SSHJ_0_3
2011-06-16 00:04:49,891 INFO  [net.schmizz.sshj.transport.TransportImpl] (ajp-127.0.0.1-8009-16) Server identity string: SSH-2.0-OpenSSH_5.1
2011-06-16 00:04:49,891 INFO  [net.schmizz.sshj.transport.KeyExchanger] (ajp-127.0.0.1-8009-16) Sending SSH_MSG_KEXINIT
2011-06-16 00:04:49,912 INFO  [net.schmizz.sshj.transport.KeyExchanger] (reader) Received SSH_MSG_KEXINIT
2011-06-16 00:04:49,915 INFO  [net.schmizz.sshj.transport.kex.DHG1] (reader) Sending SSH_MSG_KEXDH_INIT
2011-06-16 00:04:49,976 INFO  [net.schmizz.sshj.transport.KeyExchanger] (reader) Received kex followup data
2011-06-16 00:04:49,976 INFO  [net.schmizz.sshj.transport.kex.DHG1] (reader) Received SSH_MSG_KEXDH_REPLY
2011-06-16 00:04:49,979 INFO  [net.schmizz.sshj.transport.KeyExchanger] (reader) Sending SSH_MSG_NEWKEYS
2011-06-16 00:04:49,979 INFO  [net.schmizz.sshj.transport.KeyExchanger] (reader) Received SSH_MSG_NEWKEYS
2011-06-16 00:04:49,979 INFO  [net.schmizz.sshj.SSHClient] (ajp-127.0.0.1-8009-16) Key exchange took 0.088 seconds
2011-06-16 00:04:50,055 INFO  [net.schmizz.sshj.transport.TransportImpl] (ajp-127.0.0.1-8009-16) Setting active service to ssh-userauth
2011-06-16 00:04:50,055 INFO  [net.schmizz.sshj.userauth.UserAuthImpl] (ajp-127.0.0.1-8009-16) Trying `password` auth...
2011-06-16 00:04:50,055 INFO  [net.schmizz.sshj.userauth.method.AuthPassword] (ajp-127.0.0.1-8009-16) Requesting password for [AccountResource] [email protected]
2011-06-16 00:04:50,077 INFO  [net.schmizz.sshj.userauth.UserAuthImpl] (ajp-127.0.0.1-8009-16) `password` auth failed
2011-06-16 00:04:50,077 INFO  [net.schmizz.sshj.userauth.UserAuthImpl] (ajp-127.0.0.1-8009-16) Trying `keyboard-interactive` auth...
2011-06-16 00:04:50,098 INFO  [net.schmizz.sshj.userauth.method.AuthKeyboardInteractive] (reader) Requesting response for challenge `Password: `; echo=false
2011-06-16 00:04:50,212 INFO  [net.schmizz.sshj.userauth.UserAuthImpl] (ajp-127.0.0.1-8009-16) `keyboard-interactive` auth failed
net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
at net.schmizz.sshj.userauth.UserAuthImpl.authenticate(UserAuthImpl.java:109)

When I connect from the shell using ssh, it works normally. sshj is replacing JSch for us - which used to work most of the time, but not always. I was hoping that sshj would be more stable.

Any ideas on how to narrow this down? Or is there a known bug in the library?

SCP hangs when connected to dropbear server

I'm using sshj in a Remote Management Client for small, Android-based devices using the dropbear ssh server on the units.

While I can execute shell scripts fine as well as download files via SCP, I cannot seem to upload files to the unit. I can use my system's scp binary fine, and I've also confirmed that sshj works when connecting to a non-dropbear server, but when executing an SCP from sshj->dropbear, the upload hangs and a 0kb file is created at the upload destination.

If you need any more information, just let me know.

SCP Large Files -- local window exhausted

Hi,

sometimes while Transmitting large files via SCP i recive following Error:

Caused by: net.schmizz.sshj.common.SSHException: Window consumed to below 0
at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:56)
at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:49)
at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:572)
at net.schmizz.sshj.transport.Reader.run(Reader.java:79)
Caused by: net.schmizz.sshj.common.SSHRuntimeException: Window consumed to below 0
at net.schmizz.sshj.connection.channel.Window.consume(Window.java:59)
at net.schmizz.sshj.connection.channel.ChannelInputStream.receive(ChannelInputStream.java:154)
at net.schmizz.sshj.connection.channel.AbstractChannel.receiveInto(AbstractChannel.java:364)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:182)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:125)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:474)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)

Sorry but i do not understand the reason why this error occurs. Neither do i have any idea how to solve it.
I'm not sure if this is an bug or not. But i definitely can't pin down a reason why this exception happens.

Adding new Hosts to the Known Hosts File

When I try to connect to a new host for the first time via SSH, I'm asked if I trust and want to add a public host key. Is there any way to do this through SSHJ, or must the known hosts file already exist? I'm working on a windows workstation, so I have to jump through hoops to get an OpenSSH known hosts file on client machines.

sshj encountered deadlock

A deadlock occurs involving two threads: Reader thread (net.schmizz.sshj.transport.Reader) and custom thread.

  1. Reader thread obtains monitor in AbstractChannel.getResponse(boolean).
  2. Custom thread calls session.close(), which obtains the ReentrantLock in the same class as step #1.
  3. Custom thread calls session.sendClose() and waits for the monitor held by Reader thread.
  4. Reader thread waits for the ReentrantLock held by Custom thread in step #1. Therefore deadlock.

This problem occurs because Reader thread receives a Event and each Event contains the same ReentrantLock used by session.close().

We are using sshj v0.3.1. By looking at the code, this problem still exists in v0.5.0.


Here is the output from kill -3.

Found one Java-level deadlock:

"J3132-JQ455373-TS2741-QTS824034-runSshCommand":
waiting to lock monitor 0x09e16130 (object 0x9b7dfb28, a net.schmizz.sshj.connection.channel.direct.SessionChannel),
which is held by "reader"
"reader":
waiting for ownable synchronizer 0x9b7df6f8, (a java.util.concurrent.locks.ReentrantLock$NonfairSync),
which is held by "J3132-JQ455373-TS2741-QTS824034-runSshCommand"

Java stack information for the threads listed above:

"J3132-JQ455373-TS2741-QTS824034-runSshCommand":
at net.schmizz.sshj.connection.channel.AbstractChannel.sendClose(AbstractChannel.java:283)
- waiting to lock <0x9b7dfb28> (a net.schmizz.sshj.connection.channel.direct.SessionChannel)
at net.schmizz.sshj.connection.channel.AbstractChannel.close(AbstractChannel.java:259)
at XXXXXXX.core.remotecommand.ssh.RunSshCommand.runSshCommand(RunSshCommand.java:84)
at XXXXXXX.core.remotecommand.ssh.RunSshCommand.run(RunSshCommand.java:40)
at java.lang.Thread.run(Thread.java:662)
"reader":
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x9b7df6f8> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:842)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1178)
at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:186)
at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:262)
at net.schmizz.concurrent.Future.lock(Future.java:196)
at net.schmizz.concurrent.Future.set(Future.java:76)
at net.schmizz.concurrent.Event.set(Event.java:61)
at net.schmizz.sshj.connection.channel.AbstractChannel.gotResponse(AbstractChannel.java:373)
- locked <0x9b7dfb28> (a net.schmizz.sshj.connection.channel.direct.SessionChannel)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:198)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:122)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:452)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:126)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:189)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Found 1 deadlock.

SCPDownload.java example fails to run properly

This file https://github.com/shikhar/sshj/blob/53ad9d2288850717bd3e48f1999a35472ae95abe/src/main/java/examples/SCPDownload.java gives:

Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:70)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:77)
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:103)
at examples.SCPDownload.main(SCPDownload.java:31)

environment:
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b24~pre2-1)
OpenJDK Server VM (build 20.0-b12, mixed mode)

This is on Debian (Squeeze release)

Javadoc

Complete thorough Javadoc of all public API, and host somewhere

SFTP transfer "fails" on freeFTPd

SSHJ is reporting an TransportException (Broken transport; encountered EOF) when closing a remote connection to this server.

5 [main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider
794 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
842 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_3
1001 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-WeOnlyDo-wodFTPD 2.3.6.165
1015 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
1018 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
1107 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT
1175 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
1175 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY
1198 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
1223 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
1228 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 0.214 seconds
1266 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
1266 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
1266 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] [email protected]
1345 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
1345 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
1363 [main] INFO net.schmizz.sshj.connection.ConnectionImpl - Attaching `session` channel (#0)
1410 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Initialized - < session channel: id=0, recipient=1000, localWin=[winSize=2097152], remoteWin=[winSize=131072] >
1410 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Will request `sftp` subsystem
1410 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending channel request for `subsystem`
1441 [reader] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Received window adjustment for 0 bytes
1496 [main] INFO net.schmizz.sshj.sftp.SFTPEngine - Server version 3
1510 [main] INFO net.schmizz.sshj.connection.channel.direct.SessionChannel - Sending close
1574 [reader] ERROR net.schmizz.sshj.transport.TransportImpl - Dying because - net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
1576 [reader] INFO net.schmizz.sshj.connection.ConnectionImpl - Forgetting `session` channel (#0)
1576 [main] ERROR net.schmizz.concurrent.Event - <> woke to: net.schmizz.sshj.connection.ConnectionException: Broken transport; encountered EOF
1576 [reader] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to null-service
Exception in thread "main" net.schmizz.sshj.connection.ConnectionException: Broken transport; encountered EOF
        at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:32)
        at net.schmizz.sshj.connection.ConnectionException$1.chain(ConnectionException.java:26)
        at net.schmizz.concurrent.Future.error(Future.java:95)
        at net.schmizz.concurrent.FutureUtils.alertAll(FutureUtils.java:24)
        at net.schmizz.sshj.connection.channel.AbstractChannel.notifyError(AbstractChannel.java:239)
        at net.schmizz.sshj.common.ErrorNotifiable$Util.alertAll(ErrorNotifiable.java:34)
        at net.schmizz.sshj.connection.ConnectionImpl.notifyError(ConnectionImpl.java:152)
        at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:545)
        at net.schmizz.sshj.transport.Reader.run(Reader.java:79)
Caused by: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
        at net.schmizz.sshj.transport.Reader.run(Reader.java:70)

Steps to reproduce:

  1. Install [freeFTPd](http://www.freesshd.com/?ctt=download) (use default configuration, be sure to add an FTP user).
  2. Modify the following class to connect to the SSH server you configured:
    import net.schmizz.sshj.SSHClient;
    import net.schmizz.sshj.sftp.SFTPEngine;
    import net.schmizz.sshj.sftp.SFTPClient;
    import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
    

    public class SSHTest {
    public static void main(String[] args) throws Exception {
    SSHClient ssh = new SSHClient();
    ssh.addHostKeyVerifier(new PromiscuousVerifier());
    ssh.connect("127.0.0.1", 22);
    ssh.authPassword("test", "test");

        SFTPClient sftp = ssh.newSFTPClient();
        sftp.close();
    
        ssh.disconnect();
    }
    

    }

  3. Compile and run the class.

We should have an option to disable setting file attributes post-SFTP file transfer

We're running into the following issue:

  1. Client using sshj begins file transfer.
  2. File entry appears on SFTP server.
  3. Server process moves the file to another location as soon as it sees the file.
  4. Client using sshj completes the file transfer.
  5. Client using sshj sends command to set file attributes it sees locally on the remote file, but it doesn't exist at the same path on the server. Throws a "No such file" SFTPException.

It seems like sshj should either:

  • Have the option to disable step 5.
  • Separate these FTP commands. If someone needs to duplicate local file attributes, they should also send a request for that. If not, then they shouldn't be forced to.

See net.schmizz.sshj.sftp.SFTPFileTransfer.Uploader.upload(). engine.setAttributes() is what throws the SFTPException in step 5.

Visible as a maven artifact N

Is there any hope for commons-net-ssh to be available as a maven artifact on some well-known maven repostory (at best, one visible by the wonderful mvnbrowser site) ?

intermittent key exchange failures

Reported by several people. Non-deterministic, but can be reproduced by trying to connect in a loop loads of times.

net.schmizz.sshj.transport.TransportException: [KEY_EXCHANGE_FAILED] KeyExchange signature verification failed
    at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:156)
    at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:372)
    at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:475)
    at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
    at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:72)

"Request failed" error message

Hi,

I am running the following code (which has been nullified for security reasons) which tries to upload a file from my Windows XP desktop machine to a Windows Server 2008 with SSH enabled.

import java.io.File;
import java.io.IOException;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.xfer.scp.SCPFileTransfer;

public class SSHSCP {

    public static void main(String[] args)
            throws IOException, ClassNotFoundException {
        SSHClient ssh = new SSHClient();

        ssh.loadKnownHosts(new File("C:\\.ssh\\known_hosts"));
        ssh.connect("test.com");
        ssh.authPassword("test_user", "test_pass");
        try {
            SCPFileTransfer transfer = ssh.newSCPFileTransfer();         
            transfer.upload("C:\\test.txt", "/test");                        
        } finally {
            ssh.disconnect();
        }
    }
}

After using OpenSSH to create a "known_hosts" file I then run the program which produces the following error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" net.schmizz.sshj.connection.ConnectionException: Request failed
at net.schmizz.sshj.connection.channel.AbstractChannel.gotResponse(AbstractChannel.java:397)
at net.schmizz.sshj.connection.channel.AbstractChannel.handle(AbstractChannel.java:202)
at net.schmizz.sshj.connection.ConnectionImpl.handle(ConnectionImpl.java:125)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:474)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:127)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:195)
at net.schmizz.sshj.transport.Reader.run(Reader.java:72)
Java Result: 1

I am able to connect fine using a third party client like PSCP.exe and the SSH server logs the fact that the above Java program successfully logs in:

SSH connection attempt.
SSH test_user successfully logged on using password.

For some strange reason it then fails to send the file. Any ideas what could be going wrong?

Thanks

shell.changeWindowDimensions doesn't have any effect

I'm trying to change the terminal window size on the fly with shell.changeWindowDimensions(int, int, int, int) but it doesn't seem to have any effect. I initially set the window size with:

    session.allocatePTY("ansi", 80, 24, 640, 480, new EnumMap<PTYMode, Integer>(PTYMode.class));

The above code works to initialize the window size and set the terminal type, however, subsequent calls to changeWindowDimensions don't work. Perhaps I am using the method incorrectly?

My full snippet of code looks like:

    // Create a session
    session = client.startSession();    

    // Create a PTY with default size
    session.allocatePTY("ansi", 80, 24, 640, 480, new EnumMap<PTYMode, Integer>(PTYMode.class));

    // Create a shell
    final Shell shell = session.startShell();        

    // Now attempt to change the window size
    shell.changeWindowDimensions(80, 48, 640, 960);

Sudo commands failing

I am having a problem when ever I try to execute a command that requires sudo access. The commands work fine without sudo, but as soon as the command is prefixed with sudo, it will not work. I have run the exact same commands on the actual remote server and they work fine, but over sshj they don't.

LocalPortForwarding doesn't free the port after SSH is disconnected

We use sshj 0.5.0

After LocalWorkForwarder has done it's work we want to close the socket and free the port. But at the moment there's no way to do it. The thread with LocalPortForwarder.listen() is alive and the port is busy even if ssh.close() and thread.interrupt() are called().

In the code below we reuse the port for another LocalPortForwarder and it throws java.net.BindException: "Address already in use"

import net.schmizz.sshj.SSHClient;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.*;
import java.io.*;
import java.net.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;

public class LocalPF {
    private static final int PORT = 22100;
    private static final String REMOTE_HOST = "www.google.com";
    private static final int REMOTE_PORT = 80;

    private static final Logger LOG = LoggerFactory.getLogger(LocalPF.class);

    public static void main(String... args) throws Exception {

        for(int i = 0; i < 100; i++) {
            LOG.info("Try {}", i);

            final SSHClient ssh = new SSHClient();
            ssh.addHostKeyVerifier(new PromiscuousVerifier());

            ssh.connect("localhost");
            try {

                ssh.authPassword("user", "password");

                Thread thread = new Thread( new Runnable() {
                    public void run() {
                        try {
                            ssh.newLocalPortForwarder(new InetSocketAddress("localhost", PORT), REMOTE_HOST, REMOTE_PORT).listen();
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

                LOG.info("Try {}: starting port-forwarting", i);
                thread.start();

                Thread.sleep(3*1000);

                LOG.info("Try {}: getting http://localhost:22100 - started", i);
                URL url = new URL("http://localhost:22100");
                InputStream is = url.openStream();
                while(is.read() != -1) {};
                is.close();
                LOG.info("Try {}: getting http://localhost:22100 - finished", i);

                LOG.info("Try {}: interrupting the thread with port-forwarding", i);
                thread.interrupt();

                Thread.sleep(1000);
            } finally {
                LOG.info("Try {}: SSH disconnecting", i);
                ssh.disconnect();
                LOG.info("Try {}: SSH disconnected", i);
            }

        }
    }
}

The log:

2 [main] INFO LocalPF - Try 0
10 [main] INFO net.schmizz.sshj.common.SecurityUtils - BouncyCastle not registered, using the default JCE provider
395 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
414 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_4_1
419 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-OpenSSH_5.1p1 Debian-6ubuntu2
420 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
423 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
444 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT
474 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
475 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY
486 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
486 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
499 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 0.079 seconds
522 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
523 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
524 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] oleg@localhost
544 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
545 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
545 [main] INFO LocalPF - Try 0: starting port-forwarting
546 [Thread-2] INFO net.schmizz.sshj.connection.channel.direct.LocalPortForwarder - Listening on localhost/127.0.0.1:22100
3545 [main] INFO LocalPF - Try 0: getting http://localhost:22100 - started
3564 [Thread-2] INFO net.schmizz.sshj.connection.channel.direct.LocalPortForwarder - Got connection from /127.0.0.1:44483
3571 [Thread-2] INFO net.schmizz.sshj.connection.ConnectionImpl - Attaching `direct-tcpip` channel (#0)
3610 [reader] INFO net.schmizz.sshj.connection.channel.direct.LocalPortForwarder$DirectTCPIPChannel - Initialized - < direct-tcpip channel: id=0, recipient=0, localWin=[winSize=2097152], remoteWin=[winSize=2097152] >
3656 [soc2chan] INFO net.schmizz.sshj.common.StreamCopier - 0.150390625 KiB transferred  in 0.042 seconds (3.5807291666666665 KiB/s)
3657 [sockmon] INFO net.schmizz.sshj.connection.channel.direct.LocalPortForwarder$DirectTCPIPChannel - Sending close
3658 [reader] INFO net.schmizz.sshj.connection.channel.direct.LocalPortForwarder$DirectTCPIPChannel - Got close
3658 [reader] INFO net.schmizz.sshj.connection.ConnectionImpl - Forgetting `direct-tcpip` channel (#0)
3658 [chan2soc] INFO net.schmizz.sshj.common.StreamCopier - 0.4658203125 KiB transferred  in 0.043 seconds (10.833030523255815 KiB/s)
3792 [main] INFO LocalPF - Try 0: getting http://localhost:22100 - finished
3792 [main] INFO LocalPF - Try 0: interrupting the thread with port-forwarding
4792 [main] INFO LocalPF - Try 0: SSH disconnecting
4795 [main] INFO LocalPF - Try 0: SSH disconnected
4796 [main] INFO LocalPF - Try 1
4803 [main] WARN net.schmizz.sshj.DefaultConfig - Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
4803 [main] INFO net.schmizz.sshj.transport.TransportImpl - Client identity string: SSH-2.0-SSHJ_0_4_1
4814 [main] INFO net.schmizz.sshj.transport.TransportImpl - Server identity string: SSH-2.0-OpenSSH_5.1p1 Debian-6ubuntu2
4821 [main] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_KEXINIT
4823 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
4834 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Sending SSH_MSG_KEXDH_INIT
4872 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received kex followup data
4872 [reader] INFO net.schmizz.sshj.transport.kex.DHG1 - Received SSH_MSG_KEXDH_REPLY
4881 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Sending SSH_MSG_NEWKEYS
4881 [reader] INFO net.schmizz.sshj.transport.KeyExchanger - Received SSH_MSG_NEWKEYS
4883 [main] INFO net.schmizz.sshj.SSHClient - Key exchange took 0.062 seconds
4921 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-userauth
4922 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - Trying `password` auth...
4922 [main] INFO net.schmizz.sshj.userauth.method.AuthPassword - Requesting password for [AccountResource] oleg@localhost
4943 [main] INFO net.schmizz.sshj.userauth.UserAuthImpl - `password` auth successful
4943 [main] INFO net.schmizz.sshj.transport.TransportImpl - Setting active service to ssh-connection
4943 [main] INFO LocalPF - Try 1: starting port-forwarting
java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method)
    at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:365)
    at java.net.ServerSocket.bind(ServerSocket.java:319)
    at java.net.ServerSocket.bind(ServerSocket.java:277)
    at net.schmizz.sshj.connection.channel.direct.LocalPortForwarder.<init>(LocalPortForwarder.java:114)
    at net.schmizz.sshj.SSHClient.newLocalPortForwarder(SSHClient.java:587)
    at LocalPF$1.run(LocalPF.java:42)
    at java.lang.Thread.run(Thread.java:619)

test on android

  • can try with slf4j-android
  • apparently android includes bouncycastle?

SSH Agent integration

Is there any interest in providing ssh agent integration, similar to that provided by Mina? This requires some sort of native library to access the unix socket (Mina use the apache runtime I believe), so would probably need to be made optional.

Any thoughts?

rport forwarding - unstable

hi,

while using sshj against openssh with rport forwarding enabled

sshClient.getRemotePortForwarder().bind(new Forward(p), new SocketForwardingConnectListener(new InetSocketAddress("localhost", localPort)));

i am getting a lot of disconnects (after some minutes, but never got it to an hour)

server log:

Jan 12 14:37:43 catbox sshd[11984]: channel_by_id: 4: bad id: channel free
Jan 12 14:37:43 catbox sshd[11984]: Disconnecting: Received data for nonexistent channel 4.

client log:

2012-01-12 14:37:11,235 ERROR [net.schmizz.sshj.transport.TransportImpl]  Dying because - net.schmizz.sshj.transport.TransportException: [PROTOCOL_ERROR] Disconnected; server said: Received data for nonexistent channel 4.
2012-01-12 14:37:20,785 ERROR [net.schmizz.sshj.common.StreamCopier]  In pipe from java.net.SocketInputStream@4434d2ab to < ChannelOutputStream for Channel #0 >: net.schmizz.sshj.transport.TransportException: Broken pipe
2012-01-12 14:37:20,785 ERROR [net.schmizz.sshj.transport.TransportImpl]  Dying because - net.schmizz.sshj.transport.TransportException: Broken pipe
2012-01-12 14:37:20,786 ERROR [net.schmizz.concurrent.Promise]  <<copyDone>> woke to: net.schmizz.sshj.transport.TransportException: Broken pipe

note: log timestamps don't fit because one hosts clock is off some seconds
edit: changed title to reflect severity

It is impossible to execute some commands ((

I try to execute two commands in one session and I receive an error "This session channel is all used up"!!!
How I can carry out some commands in one SSH sessions??
version: sshj-0.5.0.zip

My example:

        client = new SSHClient();
        client.addHostKeyVerifier(new HostKeyVerifier() {
            public boolean verify(String s, int i, PublicKey publicKey) {
                return true;
            }
        });
        client.connect(server);
        client.authPassword(userName, pass);
        session = client.startSession();
        exec(session, "pwd");
        exec(session, "ls -l");

        public void exec(Session session, String commands) throws Exception {
            final Session.Command cmd = session.exec(command);
            cmd.join();

            InputStream in = cmd.getInputStream();
            System.out.println(IOUtils.readFully(in));

            InputStream er = cmd.getErrorStream();
            System.out.println(IOUtils.readFully(er));
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.