public class FTPcommand {
public List ftpcmd(HostBean hBean,String command) {
Connection conn=new Connection(hBean.getUrl());
List fileList=new ArrayList();
try {
conn.connect();
boolean isAuthenticated=conn.authenticateWithPassword(hBean.getUsername(),
hBean.getPassword());
if (isAuthenticated==false)
throw new IOException("Authentication failed.");
Session sess = conn.openSession();
sess.execCommand(command);
InputStream stdout=new StreamGobbler(sess.getStdout());
BufferedReader br=new BufferedReader(
new InputStreamReader(stdout));
while (true) {
String line=br.readLine();
if (line==null || line.contains("exit command"))
break;
fileList.add(line);
}
sess.close();
} catch (IOException e) {
e.printStackTrace(System.err);
} finally {
conn.close();
}
return fileList;
}
}
public List ftpcmd(HostBean hBean,String command) {
Connection conn=new Connection(hBean.getUrl());
List fileList=new ArrayList();
try {
conn.connect();
boolean isAuthenticated=conn.authenticateWithPassword(hBean.getUsername(),
hBean.getPassword());
if (isAuthenticated==false)
throw new IOException("Authentication failed.");
Session sess = conn.openSession();
sess.execCommand(command);
InputStream stdout=new StreamGobbler(sess.getStdout());
BufferedReader br=new BufferedReader(
new InputStreamReader(stdout));
while (true) {
String line=br.readLine();
if (line==null || line.contains("exit command"))
break;
fileList.add(line);
}
sess.close();
} catch (IOException e) {
e.printStackTrace(System.err);
} finally {
conn.close();
}
return fileList;
}
}