0

JSCH を使用して SFTP サーバーからファイルを取得しようとしています。ローカル ホストからは問題なくファイルを取得していますが、クラウド サーバー (SAP Cloud Platform) からは、JSCH からこの Connection Is Closed By Foreign Host 例外が発生します。システムのプロキシとポートを取得し、リクエストでプロキシを設定しています。何度か質問されたのを見たことがありますが、どれも私の問題を解決していません。コード スニペット:

String SFTPHOST = "hostname";
int    SFTPPORT = 22;
String SFTPUSER = "username";
String SFTPPASS = "password";
String SFTPWORKINGDIR = "directory";

Session     session     = null;
Channel     channel     = null;
ChannelSftp channelSftp = null;

try{
    String proxyHost = System.getProperty("https.proxyHost");
    String proxyPort = System.getProperty("https.proxyPort");

    JSch jsch = new JSch();
    session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
    session.setPassword(SFTPPASS);

    if(proxyHost != null && proxyPort != null) {
        ProxyHTTP  proxy = new ProxyHTTP(proxyHost, Integer.parseInt(proxyPort));
        session.setProxy(proxy);
    }
    java.util.Properties config = new java.util.Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect();
    channel = session.openChannel("sftp");
    channel.connect();
    channelSftp = (ChannelSftp)channel;
    channelSftp.cd(SFTPWORKINGDIR);
    Vector filelist = channelSftp.ls(SFTPWORKINGDIR);
    for(int i=0; i<filelist.size();i++){
        LsEntry entry = (LsEntry) filelist.get(i);
        response.getWriter().append(entry.getFilename());
    }

}catch(Exception ex){
    ex.printStackTrace();
}
4

0 に答える 0