use of cc.arduino.packages.ssh.SSHConfigFileSetup 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;
}
Aggregations