我正在使用JSCH进行一些SFTP操作:

JSch jsch = new JSch();
Session session = null;
ChannelSftp sftpChannel = null;
try {
    session = jsch.getSession(user, host, Integer.valueOf(port));
    session.setConfig(JSCH_OPTIONS);
    session.setPassword(password);
    session.connect();
    Channel channel = session.openChannel(SFTP_CHANNEL_ID);
    channel.connect();
    sftpChannel = (ChannelSftp) channel;

    // some sftp operations

} catch (Exception e) {
    log.error("Error while SFTP session", e);
} finally {
    sftpChannel.exit();
    session.disconnect();
}

我的问题是:当我完成时,是否足以在会话对象上调用disconnect(),或者通道上的exit()是必须的?谢谢!

更新:我检查了行为,没有错误,但我不太确定套接字/等是否正确清理 .