You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Zabee Ulla (JIRA)" <ji...@apache.org> on 2019/06/04 12:53:00 UTC
[jira] [Created] (SSHD-922) CD - change director is not working.
clientSession.executeRemoteCommand("cd " + argDirectory)
Zabee Ulla created SSHD-922:
-------------------------------
Summary: CD - change director is not working. clientSession.executeRemoteCommand("cd " + argDirectory)
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
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));
}
}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org