Skip to content
Snippets Groups Projects
Commit f5b702e0 authored by tjc's avatar tjc
Browse files

keep prompting for login of failure

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3390 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 4fe647fa
No related branches found
No related tags found
No related merge requests found
......@@ -142,139 +142,138 @@ public class SshPSUClient extends Thread
{
ConfigurationLoader.initialize(false);
if(!setLogin())
return;
// Create a password authentication instance
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
user = ufield.getText().trim();
pwd.setUsername(user);
pwd.setPassword(new String(pfield.getPassword()));
// Make a client connection
SshClient ssh = new SshClient();
hostname = hostfield.getText().trim();
if(portfield.getText().trim().equals(""))
port = -1;
else
port = Integer.parseInt(portfield.getText().trim());
int result = AuthenticationProtocolState.FAILED;
SshClient ssh = null;
// login
while(result != AuthenticationProtocolState.COMPLETE)
{
if(!setLogin())
return;
// Create a password authentication instance
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
user = ufield.getText().trim();
pwd.setUsername(user);
pwd.setPassword(new String(pfield.getPassword()));
// Make a client connection
ssh = new SshClient();
hostname = hostfield.getText().trim();
if(portfield.getText().trim().equals(""))
port = -1;
else
port = Integer.parseInt(portfield.getText().trim());
if(port < 0)
ssh.connect(hostname);
else
ssh.connect(hostname,port);
if(port < 0)
ssh.connect(hostname);
else
ssh.connect(hostname,port);
// Try the authentication
int result = ssh.authenticate(pwd);
// Evaluate the result
if(result == AuthenticationProtocolState.COMPLETE)
// Try the authentication
result = ssh.authenticate(pwd);
}
// prompt for local listfile
if(listfilepath == null)
{
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
listfilepath = chooser.getSelectedFile().getAbsolutePath();
else
return;
}
SftpClient sftp = ssh.openSftpClient();
// loop over sequence files in the listfile
Vector seqfile = readListFile(listfilepath);
for(int i=0; i<seqfile.size();i++)
{
if(listfilepath == null)
String filepath = (String)seqfile.get(i);
int index = filepath.lastIndexOf(System.getProperty("file.separator"));
String filename = filepath;
if(index > -1)
filename = filename.substring(index+1);
try
{
JFileChooser chooser = new JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
listfilepath = chooser.getSelectedFile().getAbsolutePath();
else
return;
wdir = wdir+"/"+user;
sftp.mkdir(wdir);
wdir = wdir+"/"+program+"/";
sftp.mkdir(wdir);
sftp.put(filepath, wdir+filename);
}
catch(IOException ioe)
{}
SessionChannelClient session = ssh.openSessionChannel();
SftpClient sftp = ssh.openSftpClient();
String outputfile = wdir+filename+".out";
final String actualCMD;
// loop over sequence files in the listfile
Vector seqfile = readListFile(listfilepath);
for(int i=0; i<seqfile.size();i++)
if( (cmd.indexOf("fasta33") > -1) ||
(cmd.indexOf("fastx33") > -1) )
{
String filepath = (String)seqfile.get(i);
int index = filepath.lastIndexOf(System.getProperty("file.separator"));
String filename = filepath;
if(index > -1)
filename = filename.substring(index+1);
try
{
wdir = wdir+"/"+user;
sftp.mkdir(wdir);
wdir = wdir+"/"+program+"/";
sftp.mkdir(wdir);
sftp.put(filepath, wdir+filename);
}
catch(IOException ioe)
{}
if(settings.getProperty(db) != null)
db = settings.getProperty(db);
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+wdir+filename+" "+db;
}
else
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+db+" "+wdir+filename;
// run the application
if(System.getProperty("debug") != null)
System.out.println(actualCMD);
session.executeCommand(actualCMD);
// Reading from the session InputStream
StdoutStdErrHandler stdouth = new StdoutStdErrHandler(session, true);
StdoutStdErrHandler stderrh = new StdoutStdErrHandler(session, false);
SessionChannelClient session = ssh.openSessionChannel();
String outputfile = wdir+filename+".out";
final String actualCMD;
if( (cmd.indexOf("fasta33") > -1) ||
(cmd.indexOf("fastx33") > -1) )
{
if(settings.getProperty(db) != null)
db = settings.getProperty(db);
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+wdir+filename+" "+db;
}
else
actualCMD = bsub+" -o "+ outputfile +" -e "+ outputfile + ".err " +
cmd+" "+db+" "+wdir+filename;
// run the application
if(System.getProperty("debug") != null)
System.out.println(actualCMD);
session.executeCommand(actualCMD);
// Reading from the session InputStream
StdoutStdErrHandler stdouth = new StdoutStdErrHandler(session, true);
StdoutStdErrHandler stderrh = new StdoutStdErrHandler(session, false);
stdouth.start();
stderrh.start();
boolean isFile = false;
try
{
// make sure we hang around for stdout
while(stdouth.isAlive() || stderrh.isAlive())
Thread.currentThread().sleep(10);
isFile = waitUntilFileAppears(sftp, filename+".out");
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
stdouth.start();
stderrh.start();
boolean isFile = false;
try
{
// make sure we hang around for stdout
while(stdouth.isAlive() || stderrh.isAlive())
Thread.currentThread().sleep(10);
isFile = waitUntilFileAppears(sftp, filename+".out");
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
if(System.getProperty("debug") != null)
{
// stdout & stderr
System.out.println(stdouth.getOutput());
System.out.println(stderrh.getOutput());
}
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// sftp.get(outputfile, os);
// System.out.println(os.toString());
sftp.get(outputfile, filepath+".out");
completed = true;
session.close();
if(System.getProperty("debug") != null)
{
// stdout & stderr
System.out.println(stdouth.getOutput());
System.out.println(stderrh.getOutput());
}
// Quit
sftp.quit();
ssh.disconnect();
}
else
JOptionPane.showMessageDialog(null,
"Problem logging in!\nCheck username and password.",
"Authentication Problem",
JOptionPane.ERROR_MESSAGE);
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// sftp.get(outputfile, os);
// System.out.println(os.toString());
sftp.get(outputfile, filepath+".out");
completed = true;
session.close();
}
} catch(IOException ioe){}
// Quit
sftp.quit();
ssh.disconnect();
}
catch(IOException ioe){}
finally
{
if(completed)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment