1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > java堆栈信息 linux_java - Java程序无法从Linux服务器远程读取文件 - 堆栈内存溢出...

java堆栈信息 linux_java - Java程序无法从Linux服务器远程读取文件 - 堆栈内存溢出...

时间:2023-03-15 01:07:24

相关推荐

java堆栈信息 linux_java - Java程序无法从Linux服务器远程读取文件 - 堆栈内存溢出...

我想从Linux服务器上通过Java程序远程访问文件。我已经编写了此代码,但无法正常工作。

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();

}

}

我的程序没有抛出任何错误,我可以在控制台上看到“服务器已连接”消息,然后挂起,没有给出任何其他输出,并且它没有终止。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。