簡體   English   中英

使用私鑰身份驗證來保護FTP

[英]Secure FTP using private key authentication

我正在使用JSCH庫在兩個服務器之間執行sftp。 但是,我無法使用getResource()將文件加載到URL ,因此在運行時會出錯。 我檢查了權限,它們是600,所以我們應該可以閱讀它。

    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());

在加載資源或路徑時我缺少什么嗎?

為什么不使用File.toURL

File file = new File("/home/dev85adm/.ssh/id_rsa");
if (file.exists()) {
    URL keyFileURL = file.toURL();
    //...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM