Search in sources :

Example 1 with SSHClientSetupChainRing

use of cc.arduino.packages.ssh.SSHClientSetupChainRing in project arduino-eclipse-plugin by Sloeber.

the class SSHUpload method uploadUsingPreferences.

@Override
public boolean uploadUsingPreferences(IFile hexFile, BoardDescriptor boardDescriptor, IProgressMonitor monitor) {
    boolean ret = true;
    if (boardDescriptor.usesProgrammer()) {
        this.myHighLevelConsoleStream.println(Messages.Upload_error_network);
        return false;
    }
    Session session = null;
    SCP scp = null;
    try {
        JSch jSch = new JSch();
        SSHClientSetupChainRing sshClientSetupChain = new SSHConfigFileSetup(new SSHPwdSetup());
        BoardPort boardPort = new BoardPort();
        boardPort.setBoardName(this.myHost);
        session = sshClientSetupChain.setup(boardPort, jSch);
        if (session != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password");
            session.connect(30000);
            scp = new SCP(session);
            SSH ssh = new SSH(session);
            this.myHighLevelConsoleStream.println(Messages.Upload_sending_sketch + hexFile + Messages.Upload_to + this.myHost);
            scpFiles(scp, hexFile);
            this.myHighLevelConsoleStream.println(Messages.Upload_sketch_on_yun);
            String remoteUploadCommand = Common.getBuildEnvironmentVariable(this.myProject, // $NON-NLS-1$ //$NON-NLS-2$
            "A.TOOLS." + this.myUpLoadTool.toUpperCase() + "_REMOTE.UPLOAD.PATTERN", // $NON-NLS-1$
            "run-avrdude /tmp/sketch.hex ");
            // $NON-NLS-1$
            this.myHighLevelConsoleStream.println("merge-sketch-with-bootloader.lua /tmp/sketch.hex");
            ret = // $NON-NLS-1$
            ssh.execSyncCommand(// $NON-NLS-1$
            "merge-sketch-with-bootloader.lua /tmp/sketch.hex", // $NON-NLS-1$
            this.myOutconsole, this.myErrconsole);
            // $NON-NLS-1$
            this.myHighLevelConsoleStream.println("kill-bridge");
            // $NON-NLS-1$
            ssh.execSyncCommand("kill-bridge", this.myOutconsole, this.myErrconsole);
            this.myHighLevelConsoleStream.println(remoteUploadCommand);
            ret = ret && ssh.execSyncCommand(remoteUploadCommand, this.myOutconsole, this.myErrconsole);
        }
    } catch (JSchException e) {
        String message = e.getMessage();
        String errormessage = new String();
        if (Messages.Upload_auth_cancel.equals(message) || Messages.Upload_auth_fail.equals(message)) {
            errormessage = new String(Messages.Upload_error_auth_fail) + this.myHost;
            // TODO add to ask if if the user wants to remove the password
            PasswordManager.ErasePassword(this.myHost);
        }
        if (e.getMessage().contains(Messages.Upload_connection_refused)) {
            errormessage = new String(Messages.Upload_error_connection_refused) + this.myHost;
        }
        this.myHighLevelConsoleStream.println(errormessage);
        this.myHighLevelConsoleStream.println(message);
        return false;
    } catch (Exception e) {
        this.myHighLevelConsoleStream.println(e.getMessage());
        return false;
    } finally {
        if (scp != null) {
            scp.close();
        }
        if (session != null) {
            session.disconnect();
        }
    }
    return ret;
}
Also used : SSHClientSetupChainRing(cc.arduino.packages.ssh.SSHClientSetupChainRing) JSchException(com.jcraft.jsch.JSchException) SCP(cc.arduino.packages.ssh.SCP) BoardPort(cc.arduino.packages.BoardPort) SSHPwdSetup(cc.arduino.packages.ssh.SSHPwdSetup) SSH(cc.arduino.packages.ssh.SSH) JSch(com.jcraft.jsch.JSch) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException) Session(com.jcraft.jsch.Session) SSHConfigFileSetup(cc.arduino.packages.ssh.SSHConfigFileSetup)

Aggregations

BoardPort (cc.arduino.packages.BoardPort)1 SCP (cc.arduino.packages.ssh.SCP)1 SSH (cc.arduino.packages.ssh.SSH)1 SSHClientSetupChainRing (cc.arduino.packages.ssh.SSHClientSetupChainRing)1 SSHConfigFileSetup (cc.arduino.packages.ssh.SSHConfigFileSetup)1 SSHPwdSetup (cc.arduino.packages.ssh.SSHPwdSetup)1 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 Session (com.jcraft.jsch.Session)1 IOException (java.io.IOException)1