JSCHライブラリを使用して、2つのサーバー間でsftpを実行しています。しかし、私はファイルにgetResource()
を使用してロードすることができません。実行時にエラーが発生します。私はパーミッションをチェックして、600であるので、それを読むことができるはずです。秘密鍵認証を使用した安全なFTP
JSch jsch = new JSch();
File file = new File("/home/xxxxxx/.ssh/id_rsa");
Session session = null;
URL keyFileURL = null;
URI keyFileURI = null;
if (file.exists())
{
keyFileURL = SecureFTP.class.getClassLoader().getResource("/home/xxxxxx/.ssh/id_rsa");
if (keyFileURL == null)
{
System.out.println("what");
throw new RuntimeException("Key file not found in classpath");
}
}
try{
keyFileURI = keyFileURL.toURI();
}
catch(Exception URISyntaxException)
{
System.out.println("Wrong URL. LOL");
}
jsch.addIdentity(new File(keyFileURI).getAbsolutePath());
リソースやパスの読み込みに何か不足していますか?
どのファイルを使用していませんか?キーファイル?プログラムがうまくコンパイルされると、実行時にエラーが発生します。 – roymustang86
/home/xxxxxx/.ssh/id_rsaはクラスパスにありますか?それはすべきでしょうか? "/ home"ディレクトリの下にファイルを取得したいようです。私はあなたのアプリのリソースとは思わない? –