Hi, I have attached a java file ApacheSshClient.java. It makes a connection to sftpserver using apache ssh library. You need to put mina-core and sshd-core jar in the classpath. After running this class, I get following exception at client side:
2012-04-12 22:46:18,623 [NioProcessor-2 ] INFO UserAuthPassword - Received SSH_MSG_USERAUTH_SUCCESS Authenticated.... 2012-04-12 22:46:18,629 [main ] INFO ChannelSubsystem - Send SSH_MSG_CHANNEL_OPEN on channel 0 2012-04-12 22:46:18,631 [NioProcessor-2 ] INFO ClientSessionImpl - Received SSH_MSG_CHANNEL_OPEN_CONFIRMATION on channel 0 2012-04-12 22:46:18,632 [NioProcessor-2 ] INFO ChannelSubsystem - Send SSH_MSG_CHANNEL_REQUEST subsystem... 2012-04-12 22:46:18,633 [InputStreamPump] INFO ChannelSubsystem - Send SSH_MSG_CHANNEL_EOF on channel 0 2012-04-12 22:46:18,636 [NioProcessor-2 ] INFO ClientSessionImpl - Closing session 2012-04-12 22:46:18,637 [NioProcessor-2 ] INFO ChannelSubsystem - Closing channel 0 immediately I am using apache sshd server. At the server side, I got below exceptions: 2012-04-12 22:46:18,633 [NioProcessor-16] INFO ChannelSession - Received channel request: subsystem 2012-04-12 22:46:18,639 [NioProcessor-16] INFO ChannelSession - Received SSH_MSG_CHANNEL_EOF on channel 0 2012-04-12 22:46:18,639 [NioProcessor-16] INFO ServerSession - Closing session 2012-04-12 22:46:18,639 [NioProcessor-16] INFO ChannelSession - Closing channel 0 immediately 2012-04-12 22:46:18,639 [Thread-18 ] INFO ChannelSession - Send SSH_MSG_CHANNEL_EOF on channel 0 2012-04-12 22:46:18,640 [Thread-18 ] INFO ChannelSession - Send SSH_MSG_CHANNEL_REQUEST exit-status on channel 0 2012-04-12 22:46:18,640 [Thread-18 ] INFO ChannelSession - Send SSH_MSG_CHANNEL_CLOSE on channel 0 The server throws this exception because client sends SSH_MSG_CHANNEL_EOF request to the server. My question is why client is closing the connection after successful authentication? When I run ApacheSshClient.java class in debug mode, I get below exceptions at client side: 2012-04-12 22:52:42,577 [NioProcessor-2 ] INFO UserAuthPassword - Received SSH_MSG_USERAUTH_SUCCESS Authenticated.... 2012-04-12 22:52:48,985 [main ] INFO ChannelSubsystem - Send SSH_MSG_CHANNEL_OPEN on channel 0 2012-04-12 22:52:49,186 [NioProcessor-2 ] INFO ClientSessionImpl - Received SSH_MSG_CHANNEL_OPEN_CONFIRMATION on channel 0 2012-04-12 22:52:49,187 [NioProcessor-2 ] INFO ChannelSubsystem - Send SSH_MSG_CHANNEL_REQUEST subsystem... 2012-04-12 22:52:49,207 [NioProcessor-2 ] INFO ClientSessionImpl - Closing session 2012-04-12 22:52:49,210 [NioProcessor-2 ] INFO ChannelSubsystem - Closing channel 0 immediately At server side: 2012-04-12 22:52:49,195 [NioProcessor-17] INFO ChannelSession - Received channel request: subsystem 2012-04-12 22:52:49,210 [NioProcessor-17] INFO ServerSession - Closing session 2012-04-12 22:52:49,210 [NioProcessor-17] INFO ChannelSession - Closing channel 0 immediately 2012-04-12 22:52:49,228 [Thread-19 ] INFO ChannelSession - Send SSH_MSG_CHANNEL_EOF on channel 0 2012-04-12 22:52:49,228 [Thread-19 ] INFO ChannelSession - Send SSH_MSG_CHANNEL_REQUEST exit-status on channel 0 2012-04-12 22:52:49,228 [Thread-19 ] INFO ChannelSession - Send SSH_MSG_CHANNEL_CLOSE on channel 0 It seems, sftpserver is properly creating subsystem, but soon after connection gets disconnected when sftpclient closes its connection. What is the way to execute sftp specific command like put,get,pwd,cd etc... gnodet wrote: > > It's really hard to tell without more informations. > Make sure you enabled sftp support on the sshd server side, maybe provide > the sshd logs at debug level in order to see what happen. > Last, maybe a good way would be to provide a test case that I could run to > replicate your problem. > > On Thu, Apr 12, 2012 at 15:09, manojkumar16 <[email protected]> > wrote: > >> >> Hi Guillaume, >> There is no such thing... I will surely use the mailing lists for further >> communications. >> Long time back I asked for the help regarding the implementation of >> sftpclient using apache sshd library... >> My plan is to execute sftp commands in sftp subsystem mode. >> In my entry class, I have added chunk of code shown below: >> >> ClientChannel channel = >> session.createSubsystemChannel( "sftp" ); >> InputStream in = new ByteArrayInputStream( >> "ls".getBytes() ); >> channel.setIn(in); >> channel.setOut(System.out); >> channel.setErr(System.err); >> channel.open().await(); >> >> And in ChannelSubsystem.java class, below api is provided: >> >> protected void doOpen() throws Exception { >> super.doOpen(); >> log.info("Send SSH_MSG_CHANNEL_REQUEST subsystem..."); >> Buffer buffer = >> session.createBuffer(SshConstants.Message.SSH_MSG_CHANNEL_REQUEST, 0); >> buffer.putInt(recipient); >> buffer.putString("subsystem"); >> buffer.putBoolean(true); >> buffer.putString(subsystem); >> session.writePacket(buffer); >> } >> >> >> After executing the entry class I got following logs: >> 2012-04-12 18:25:14,106 [main ] INFO ChannelSubsystem >> - Send SSH_MSG_CHANNEL_OPEN on channel 0 >> 2012-04-12 18:25:18,202 [NioProcessor-2 ] INFO ClientSessionImpl >> - Received SSH_MSG_CHANNEL_OPEN_CONFIRMATION on channel 0 >> 2012-04-12 18:25:18,204 [NioProcessor-2 ] INFO ChannelSubsystem >> - Send SSH_MSG_CHANNEL_REQUEST subsystem... >> 2012-04-12 18:25:18,227 [NioProcessor-2 ] INFO ClientSessionImpl >> - Closing session >> 2012-04-12 18:25:18,230 [NioProcessor-2 ] INFO ChannelSubsystem >> - Closing channel 0 immediately >> >> >> My question here is, why is it closing the session after sending >> SSH_MSG_CHANNEL_REQUEST for subsystem? >> >> >> >> gnodet wrote: >> > >> > Unless there's a need for secrecy, using the mailing lists is usually a >> > good idea so that everyone can get involved. >> > >> > On Thu, Apr 12, 2012 at 14:47, manojkumar16 <[email protected]> >> > wrote: >> > >> >> >> >> Actually, I do not want to use Jsch library... Since, Apache sshd has >> >> provided well-written ssh library for both client and server, I want >> to >> >> focus more on implementing sftp client using apache sshd library. >> >> Can you reach me on [email protected] so that I can explain you >> >> exactly >> >> what I am doing for sftp client implementation using apache sshd >> library? >> >> >> >> >> >> David Latorre wrote: >> >> > >> >> > For SFTP-client support there are several options, in our case, we >> use >> >> > apache commons vfs with JSCH libraries. Would that work for you? >> >> > >> >> > >> >> > >> >> > >> >> > 2012/1/23 Guillaume Nodet <[email protected]>: >> >> >> Oh, I missed you were talking about sftp. The problem is that >> we've >> >> >> mostly focused on the server side, so the client side is still >> lacking >> >> >> lots of features. And the sftp support is one of them >> unfortunately. >> >> >> >> >> >> >> >> >> On Mon, Jan 23, 2012 at 09:48, Guillaume Nodet <[email protected]> >> >> wrote: >> >> >>> You can find a real working example of using the client side in >> >> Apache >> >> >>> Karaf: >> >> >>> >> >> >> https://github.com/apache/karaf/blob/trunk/client/src/main/java/org/apache/karaf/client/Main.java >> >> >>> >> >> >>> The basic idea is to open a channel which is either a "shell" >> channel >> >> >>> for an interactive session or an "exec" channel to execute a >> single >> >> >>> command and exit without any user interaction. >> >> >>> The channel has an input stream and two output streams (out and >> err) >> >> >>> which you can set to redirect to the default System.out and >> >> System.err >> >> >>> or to your own in-memory stream or whatever kind of streams you >> want. >> >> >>> >> >> >>> On Mon, Jan 23, 2012 at 08:16, manoj kumar >> <[email protected]> >> >> >>> wrote: >> >> >>>> Hi, >> >> >>>> >> >> >>>> I want to write sftp Client using apache-sshd mina client api. I >> am >> >> >>>> able to >> >> >>>> connect to sftp server using apache ssh client but I do not have >> any >> >> >>>> idea >> >> >>>> how to send sftp command to apache sshd server and how do I get >> >> result >> >> >>>> of >> >> >>>> sftp client. I am totally lost. Please guide me. I have confusion >> on >> >> >>>> below >> >> >>>> code: >> >> >>>> >> >> >>>> SshClient client = SshClient.setUpDefaultClient(); >> >> >>>> client.start(); >> >> >>>> ClientSession session = client.connect("localhost", >> >> >>>> port).await().getSession(); >> >> >>>> session.authPassword("smx", "smx"); >> >> >>>> ClientChannel channel = >> >> >>>> session.createChannel(ClientChannel.CHANNEL_SHELL); >> >> >>>> ByteArrayOutputStream sent = new ByteArrayOutputStream(); >> >> >>>> PipedOutputStream pipedIn = new >> TeePipedOutputStream(sent); >> >> >>>> channel.setIn(new PipedInputStream(pipedIn)); >> >> >>>> ByteArrayOutputStream out = new ByteArrayOutputStream(); >> >> >>>> ByteArrayOutputStream err = new ByteArrayOutputStream(); >> >> >>>> channel.setOut(out); >> >> >>>> channel.setErr(err); >> >> >>>> channel.open().await(); >> >> >>>> >> >> >>>> -- >> >> >>>> Thanks and Regards, >> >> >>>> Manoj Kumar >> >> >>>> 9535214528 >> >> >>> >> >> >>> >> >> >>> >> >> >>> -- >> >> >>> ------------------------ >> >> >>> Guillaume Nodet >> >> >>> ------------------------ >> >> >>> Blog: http://gnodet.blogspot.com/ >> >> >>> ------------------------ >> >> >>> FuseSource, Integration everywhere >> >> >>> http://fusesource.com >> >> >> >> >> >> >> >> >> >> >> >> -- >> >> >> ------------------------ >> >> >> Guillaume Nodet >> >> >> ------------------------ >> >> >> Blog: http://gnodet.blogspot.com/ >> >> >> ------------------------ >> >> >> FuseSource, Integration everywhere >> >> >> http://fusesource.com >> >> > >> >> > >> >> >> >> -- >> >> View this message in context: >> >> >> http://old.nabble.com/sshClient-in-apache-sshd-mina-tp33186423p33675023.html >> >> Sent from the Apache MINA User Forum mailing list archive at >> Nabble.com. >> >> >> >> >> > >> > >> > -- >> > ------------------------ >> > Guillaume Nodet >> > ------------------------ >> > Blog: http://gnodet.blogspot.com/ >> > ------------------------ >> > FuseSource, Integration everywhere >> > http://fusesource.com >> > >> > >> >> -- >> View this message in context: >> http://old.nabble.com/sshClient-in-apache-sshd-mina-tp33186423p33675184.html >> Sent from the Apache MINA User Forum mailing list archive at Nabble.com. >> >> > > > -- > ------------------------ > Guillaume Nodet > ------------------------ > Blog: http://gnodet.blogspot.com/ > ------------------------ > FuseSource, Integration everywhere > http://fusesource.com > > http://old.nabble.com/file/p33676989/ApacheSshClient.java ApacheSshClient.java -- View this message in context: http://old.nabble.com/sshClient-in-apache-sshd-mina-tp33186423p33676989.html Sent from the Apache MINA User Forum mailing list archive at Nabble.com.
