[
https://issues.apache.org/jira/browse/SSHD-922?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Zabee Ulla updated SSHD-922:
----------------------------
Description:
I am writing an SSHD client to execute remote Linux commands. My functionality
requires to change directories at several points. I have written and using
below code and not finding change directory working. I tried few other Linux
commands and am able to execute them perfectly except change directory. This is
blocker for me to embed and implement Apache SSHD client for my application
/**
* An implementation of an SFTP client that uses the Apache Mina library.
*/
public class MinaSftp {
_public void changeRemoteDirectory(String argDirectory)_
_throws IOException {_
_try {_
_System.out.println("Present working direcotry :\n " +
_session.executeRemoteCommand("pwd"));_
_+*String output = _session.executeRemoteCommand("cd " + argDirectory);*+_
_System.out.println("Present working direcotry :\n " +
_session.executeRemoteCommand("pwd"));_
_System.out.println("Change directory output: " + output);_
_}_
_catch (IOException ex) {_
_handleException(ex, action);_
_}_
_}_
private static Collection<ClientChannelEvent> ccEvents =
Arrays.asList(ClientChannelEvent.CLOSED);
private String _username = "userName";
private String _password = "password";
private String _host = "aValidHostName";
private ClientSession _session;
private ClientChannel _channel;
private SshClient _client;
// Some valid port number
private int portNumber = 8999;
public void connect()
throws IOException {
_client = SshClient.setUpDefaultClient();
_client.start();
ConnectFuture connectFuture = _client.connect(_username, _host, portNumber);
connectFuture.await();
_session = connectFuture.getSession();
_channel = _session.createChannel(ClientChannel.CHANNEL_SHELL);
_session.addPasswordIdentity(_password);
// TODO : fix timeout
_session.auth().verify(Integer.MAX_VALUE);
if (_session.isAuthenticated())
{ System.out.println("Authentication successful"); }
else
{ System.out.println("Authentication failed"); }
_channel.waitFor(ccEvents, 200);
}
public void disconnect() {
LOG.debug("Disconnecting from the SFTP host.");
// Disconnecting the session disconnects all of the connected channels as well.
if (_channel != null) {
try
{ _channel.close(); }
catch (Exception e)
{ // Do nothing. This is okay. }
}
if (_session != null)
{ _session.close(false); }
if (_client != null)
{ _client.stop(); }
}
private void handleException(Exception argEx, String argAction)
throws IOException
{ throw LOG.throwing(new IOException(argAction + " on the SFTP host threw an
exception.", argEx)); }
}
was:
I am writing an SSHD client to execute remote Linux commands. My functionality
requires to change directories at several points. I have written and using
below code and not finding change directory working. I tried few other Linux
commands and am able to execute them perfectly except change directory.
/**
* An implementation of an SFTP client that uses the Apache Mina library.
*/
public class MinaSftp {
private static Collection<ClientChannelEvent> ccEvents =
Arrays.asList(ClientChannelEvent.CLOSED);
private String _username = "userName";
private String _password = "password";
private String _host = "aValidHostName";
private ClientSession _session;
private ClientChannel _channel;
private SshClient _client;
// Some valid port number
private int portNumber = 8999;
_public void changeRemoteDirectory(String argDirectory)_
_throws IOException {_
_try {_
_System.out.println("Present working direcotry :\n " +
_session.executeRemoteCommand("pwd"));_
_+*String output = _session.executeRemoteCommand("cd " + argDirectory);*+_
_System.out.println("Present working direcotry :\n " +
_session.executeRemoteCommand("pwd"));_
_System.out.println("Change directory output: " + output);_
_}_
_catch (IOException ex) {_
_handleException(ex, action);_
_}_
_}_
public void connect()
throws IOException {
_client = SshClient.setUpDefaultClient();
_client.start();
ConnectFuture connectFuture = _client.connect(_username, _host, portNumber);
connectFuture.await();
_session = connectFuture.getSession();
_channel = _session.createChannel(ClientChannel.CHANNEL_SHELL);
_session.addPasswordIdentity(_password);
// TODO : fix timeout
_session.auth().verify(Integer.MAX_VALUE);
if (_session.isAuthenticated()) {
System.out.println("Authentication successful");
}
else {
System.out.println("Authentication failed");
}
_channel.waitFor(ccEvents, 200);
}
public void disconnect() {
LOG.debug("Disconnecting from the SFTP host.");
// Disconnecting the session disconnects all of the connected channels as well.
if (_channel != null) {
try {
_channel.close();
}
catch (Exception e) {
// Do nothing. This is okay.
}
}
if (_session != null) {
_session.close(false);
}
if (_client != null) {
_client.stop();
}
}
private void handleException(Exception argEx, String argAction)
throws IOException {
throw LOG.throwing(new IOException(argAction + " on the SFTP host threw an
exception.", argEx));
}
}
> CD - change directory is not working. clientSession.executeRemoteCommand("cd
> " + directory)
> -------------------------------------------------------------------------------------------
>
> Key: SSHD-922
> URL: https://issues.apache.org/jira/browse/SSHD-922
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 2.2.0
> Environment: Trying to connect to a Linux VM from Windows OS
> Reporter: Zabee Ulla
> Priority: Blocker
>
> I am writing an SSHD client to execute remote Linux commands. My
> functionality requires to change directories at several points. I have
> written and using below code and not finding change directory working. I
> tried few other Linux commands and am able to execute them perfectly except
> change directory. This is blocker for me to embed and implement Apache SSHD
> client for my application
> /**
> * An implementation of an SFTP client that uses the Apache Mina library.
> */
> public class MinaSftp {
> _public void changeRemoteDirectory(String argDirectory)_
> _throws IOException {_
> _try {_
> _System.out.println("Present working direcotry :\n " +
> _session.executeRemoteCommand("pwd"));_
> _+*String output = _session.executeRemoteCommand("cd " + argDirectory);*+_
> _System.out.println("Present working direcotry :\n " +
> _session.executeRemoteCommand("pwd"));_
> _System.out.println("Change directory output: " + output);_
> _}_
> _catch (IOException ex) {_
> _handleException(ex, action);_
> _}_
> _}_
> private static Collection<ClientChannelEvent> ccEvents =
> Arrays.asList(ClientChannelEvent.CLOSED);
> private String _username = "userName";
> private String _password = "password";
> private String _host = "aValidHostName";
> private ClientSession _session;
> private ClientChannel _channel;
> private SshClient _client;
> // Some valid port number
> private int portNumber = 8999;
>
> public void connect()
> throws IOException {
> _client = SshClient.setUpDefaultClient();
> _client.start();
> ConnectFuture connectFuture = _client.connect(_username, _host, portNumber);
> connectFuture.await();
> _session = connectFuture.getSession();
> _channel = _session.createChannel(ClientChannel.CHANNEL_SHELL);
> _session.addPasswordIdentity(_password);
> // TODO : fix timeout
> _session.auth().verify(Integer.MAX_VALUE);
> if (_session.isAuthenticated())
> { System.out.println("Authentication successful"); }
> else
> { System.out.println("Authentication failed"); }
> _channel.waitFor(ccEvents, 200);
> }
> public void disconnect() {
> LOG.debug("Disconnecting from the SFTP host.");
> // Disconnecting the session disconnects all of the connected channels as
> well.
> if (_channel != null) {
> try
> { _channel.close(); }
> catch (Exception e)
> { // Do nothing. This is okay. }
> }
> if (_session != null)
> { _session.close(false); }
> if (_client != null)
> { _client.stop(); }
> }
> private void handleException(Exception argEx, String argAction)
> throws IOException
> { throw LOG.throwing(new IOException(argAction + " on the SFTP host threw an
> exception.", argEx)); }
> }
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]