如果您看到这篇文章,表示您的 blog 已经安装成功.


   public byte[] getFileBytes(String path, String file, String[] hostInfo) throws JSchException, IOException, SftpException {
        JSch sftpClient = new JSch();
        Session session = sftpClient.getSession(hostInfo[2], hostInfo[0], PubFun.getInt(hostInfo[1]));//根据用户名,主机ip和端口获取一个Session对象
        session.setPassword(hostInfo[3]);
        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.setTimeout(20000);
        session.connect();
        System.out.println(session.toString());
        byte[] buff;
        try {
            ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
            channelSftp.connect();
            path = formatPath(path, file);
            try {
                logger.debug("try to get file:" + path);
                buff = ExcelUtil.getOutputBytes(channelSftp.get(path));
            } finally {
                channelSftp.quit();
            }
            System.out.println("===========");
        } finally {
            session.disconnect();
        }
        return buff;
    }
Last modification:January 12th, 2020 at 01:03 pm
如果觉得我的文章对你有用,请随意赞赏