hierynomus / sshj

ssh, scp and sftp for java
Apache License 2.0
2.5k stars 601 forks source link

Exception by sftp.close() #173

Open mfriendz opened 9 years ago

mfriendz commented 9 years ago

closing SFTPCient connection to a PSFTP server (www.psftp.de) dont seem to work as expected:

public static void main(String[] args) throws IOException {
    final SSHClient ssh = new SSHClient();
    ssh.addHostKeyVerifier(new PromiscuousVerifier());
    ssh.connect("psftp");
    ssh.authPassword("user", "pass");
    try {
        final SFTPClient sftp = ssh.newSFTPClient();
        try {
             sftp.put("/tmp/test.txt", "test.txt");
        } finally {
            sftp.close();      }
          } finally {
         ssh.disconnect();
    }
}
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.common.SecurityUtils$BouncyCastleRegistration run
Information: BouncyCastle registration succeeded
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.DefaultConfig initCipherFactories
Warnung: Disabling high-strength ciphers: cipher strengths apparently limited by JCE policy
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.transport.TransportImpl init
Information: Client identity string: SSH-2.0-SSHJ_0_9_2
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.transport.TransportImpl init
Information: Server identity string: SSH-2.0-PSFTPd. Secure FTP Server ready
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.connection.channel.direct.SessionChannel startSubsystem
Information: Will request `sftp` subsystem
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.transport.TransportImpl die
Schwerwiegend: Dying because - {}
net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
    at net.schmizz.sshj.transport.Reader.run(Reader.java:59)

Jan 30, 2015 4:26:29 PM net.schmizz.sshj.transport.TransportImpl$1 notifyDisconnect
Information: Disconnected - UNKNOWN
Jan 30, 2015 4:26:29 PM net.schmizz.concurrent.Promise tryRetrieve
Schwerwiegend: <<chan#0 / close>> woke to: net.schmizz.sshj.connection.ConnectionException: Broken transport; encountered EOF
Jan 30, 2015 4:26:29 PM net.schmizz.sshj.transport.TransportImpl$1 notifyDisconnect
Information: Disconnected - BY_APPLICATION
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:1)
    at net.schmizz.concurrent.Promise.deliverError(Promise.java:95)
    at net.schmizz.concurrent.Event.deliverError(Event.java:72)
    at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34)
    at net.schmizz.sshj.connection.channel.AbstractChannel.notifyError(AbstractChannel.java:218)
    at net.schmizz.sshj.connection.channel.direct.SessionChannel.notifyError(SessionChannel.java:229)
    at net.schmizz.sshj.common.ErrorNotifiable$Util.alertAll(ErrorNotifiable.java:35)
    at net.schmizz.sshj.connection.ConnectionImpl.notifyError(ConnectionImpl.java:262)
    at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:588)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:67)
Caused by: net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF
    at net.schmizz.sshj.transport.Reader.run(Reader.java:59)

If you only disconnect() without close() everything works fine... This seems to be a PSFTP server issue only??

hierynomus commented 9 years ago

Hi @mfriendz,

Which version of SSHJ did you use to reproduce this? I've added a test (https://github.com/hierynomus/sshj/blob/master/src/test/java/com/hierynomus/sshj/sftp/SFTPClientTest.java) which tries this with Apache Mina, and there it at least does not occur.

hierynomus commented 8 years ago

@mfriendz I know this is a somewhat older issue, but would you be able to generate more detailed logging?

Prefer to set these loggers in logback.xml

<logger name="net.schmizz.sshj" level="debug"/>
<logger name="net.schmizz.sshj.transport" level="trace" />
jkbaird commented 8 years ago

Encountered an issue that looks the same while running version 0.16.0. The issue is reproducible and more detailed logging is attached as requested. sshjAssertion.txt

hierynomus commented 8 years ago

Thx @jkbaird I will have a look.

hierynomus commented 8 years ago

Just to get this straight, you were running a parallell process against 2 different SSH servers? (OpenSSH 5.3 and Adtran 4.31)

jkbaird commented 8 years ago

Yes. That's correct. Connecting to two different servers in parallel process.

JD557 commented 8 years ago

I believe that I'm also having this problem (connections dying with net.schmizz.sshj.transport.TransportException: Broken transport; encountered EOF even if I call close()).

I'm connecting to a single SFTP server, but with 4 different connections (each one downloading a different file).

This happened to me with version 0.15.0. I'm upgrading today to 0.17.2, so I'll say something if the problem goes away.

tripexito commented 7 years ago

I've been using SSHJ v0.20.0 to connect using sftp to freeFTPd and I'm getting the same Exception. I've realized that it doesn't work if try to upload any file to FTP server (reading files works fine). Even if I comment the close/disconnect instruction. Please give anyone can give me some approach how to solve this. Thanks in advance.

renejahn commented 6 years ago

Running into the same problem, while everything seems to work (v0.24.0). Are there any plans to fix this issue?