gpt4 book ai didi

java - 来自具有 Java keystore 的 Java 程序的 SCP

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:35 24 4
gpt4 key购买 nike

我需要在java程序中将SCP文件(例如csv文件)发送到另一台服务器。 SCP 的 RSA key 存储在 java keystore 中。

我还没有找到任何允许执行此操作的代码。

任何人都可以提供一些示例代码或关于如何执行此操作的想法吗?

(我发现了一些适用于 id_rsa 字符串的代码。但它们是不同的格式。并且尝试提取/转换为该格式很困难)

最佳答案

Herehere是有关将 key 从 java keystore 转换为 .pem 文件的一些信息。然后就可以使用pem进行SCP了。

尝试sshj图书馆。以下是 SCP 上传的示例:

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.xfer.FileSystemFile;

import java.io.File;
import java.io.IOException;

/** This example demonstrates uploading of a file over SCP to the SSH server. */
public class SCPUpload {

public static void main(String[] args)
throws IOException, ClassNotFoundException {
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("localhost");
try {
ssh.authPublickey("/path/to/key.pem"));

// Present here to demo algorithm renegotiation - could have just put this before connect()
// Make sure JZlib is in classpath for this to work
ssh.useCompression();

final String src = System.getProperty("user.home") + File.separator + "test_file";
ssh.newSCPFileTransfer().upload(new FileSystemFile(src), "/tmp/");
} finally {
ssh.disconnect();
}
}
}

关于java - 来自具有 Java keystore 的 Java 程序的 SCP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25443360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com