我正在寻找一种使用私钥字符串创建 DefaultSftpSessionFactory 的方法。此处可用的不同功能是使用私钥资源(本地文件)。
有什么想法可以创建 SftpRemoteFileTemplate 所需的 SessionFactory?我将用户、主机和私钥作为字符串。
-谢谢
我正在寻找一种使用私钥字符串创建 DefaultSftpSessionFactory 的方法。此处可用的不同功能是使用私钥资源(本地文件)。
有什么想法可以创建 SftpRemoteFileTemplate 所需的 SessionFactory?我将用户、主机和私钥作为字符串。
-谢谢
二传手需要Resource
...
/**
* Allows you to set a {@link Resource}, which represents the location of the
* private key used for authenticating against the remote host. If the privateKey
* is not provided, then the {@link DefaultSftpSessionFactory#setPassword(String) password}
* property is mandatory (or {@link #setUserInfo(UserInfo) userInfo} that returns a
* password.
* @param privateKey The private key.
* @see JSch#addIdentity(String)
* @see JSch#addIdentity(String, String)
*/
public void setPrivateKey(Resource privateKey) {
this.privateKey = privateKey;
}
有很多种Resource
,包括ByteArrayResource
,你可以在哪里使用
setPrivateKey(new ByteArrayResource(myKeyString.getBytes());