JSch会话将在10分钟后终止

时间:2019-07-19 15:43:17

标签: java jsch

我正在使用Jsch设置与远程服务器的连接并从远程服务器执行批处理脚本。该脚本尝试将巨大的zip文件解压缩到特定位置。但是我的Java代码在约10分钟后终止。谁能帮我解决这个问题?下面是代码:返回的exitStatus为-1。

公共类RemoteScriptExec {

public static void main(String[] args) {
    long startTime = System.currentTimeMillis();
    JSch jsch = new JSch();
    Session session;
    try {
        session = jsch.getSession(username,host,port);
        session.setConfig("StrictHostKeyChecking", "no");
        session.setPassword(password);
        session.connect();
        ChannelExec channelExec = (ChannelExec) 
        session.openChannel("exec");
        channelExec.setCommand("C:\\Users\\Administrator\\extractor.bat");
        channelExec.setErrStream(System.err);
        channelExec.connect();
        InputStream in = channelExec.getInputStream();
        BufferedReader reader = new BufferedReader(new 
        InputStreamReader(in));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
        reader.close();
        int exitStatus = channelExec.getExitStatus();
        if (exitStatus > 0) {
            System.out.println("Remote script exec error! " + exitStatus);
        }
        session.disconnect();
    } catch (JSchException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }}}

我尝试过使用sendKeepAliveMsg(),setTimeout(int)等不同方法,但是没有任何效果。

0 个答案:

没有答案