I want to Access file through my java program remotely from Linux sever.I have write this code but its not working.
public static void main(String arg[]) throws FileNotFoundException
{
JSch jsch = new JSch();
Session session = null;
BufferedReader br = null;
try {
session = jsch.getSession("root", "IPServer", 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("Password");
session.connect();
System.out.println("Server is connect");
try
{
String command = "scp -f /var/log/callrec/core1.log";
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
OutputStream out = channel.getOutputStream();
InputStream in = (InputStream) channel.getInputStream();
channel.connect();
br = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("\nDone!");
}
catch(Exception e)
{
e.printStackTrace();
}
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
// } catch (SftpException e) {
// e.printStackTrace();
}
}
My program did not throw any error, i can see "server is connect" message on my console and then its hanged and not give any other output and it didn't terminate....