mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Goldstein Lyor (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SSHD-922) CD - change directory is not working. clientSession.executeRemoteCommand("cd " + directory)
Date Mon, 15 Jul 2019 16:15:00 GMT

    [ https://issues.apache.org/jira/browse/SSHD-922?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16885362#comment-16885362
] 

Goldstein Lyor commented on SSHD-922:
-------------------------------------

See https://github.com/apache/mina-sshd/blob/master/docs/client-setup.md#running-a-command-or-opening-a-shell

> 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
>            Assignee: Goldstein Lyor
>            Priority: Blocker
>
> I am writing an SSHD client to execute BASH commands on a remove Linux VM. My functionality
requires to change directories at several points. 
> I have written and using below code and not finding change directory working. I tried
a few other Linux commands and am able to execute them perfectly except change directory. 
> This is a blocker for me to embed and implement Apache SSHD client for my application.

> Please note that "pwd" output is same before and after _+*session.executeRemoteCommand("cd
" + argDirectory);*+_'s execution.
> /**
>  * 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 shellChannel;
>  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();
> shellChannel = _session.createShellChannel();
>  _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.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org


Mime
View raw message