本文整理匯總了Java中net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper類的典型用法代碼示例。如果您正苦於以下問題:Java KeyPairWrapper類的具體用法?Java KeyPairWrapper怎麽用?Java KeyPairWrapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KeyPairWrapper類屬於net.schmizz.sshj.userauth.keyprovider包,在下文中一共展示了KeyPairWrapper類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: uploadFile
import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper; //導入依賴的package包/類
@Test
public void uploadFile() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));
ssh.connect("localhost", subject.getPort());
try {
ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));
final SFTPClient sftp = ssh.newSFTPClient();
File testFile = local.newFile("fred.txt");
try {
sftp.put(new FileSystemFile(testFile), "/fred.txt");
} finally {
sftp.close();
}
} finally {
ssh.disconnect();
}
assertThat(sftpHome.getRoot().list(), is(new String[]{"fred.txt"}));
}
示例2: downloadFile
import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper; //導入依賴的package包/類
@Test
public void downloadFile() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
FileUtils.write(sftpHome.newFile("fred.txt"), "Electric boogaloo");
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));
ssh.connect("localhost", subject.getPort());
try {
ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));
final SFTPClient sftp = ssh.newSFTPClient();
try {
sftp.get("fred.txt", new FileSystemFile(new File(local.getRoot(), "fred.txt")));
} finally {
sftp.close();
}
} finally {
ssh.disconnect();
}
assertThat(FileUtils.readFileToString(new File(local.getRoot(), "fred.txt")),
is("Electric boogaloo"));
}
示例3: prepareSshConnection
import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper; //導入依賴的package包/類
private void prepareSshConnection(SSHClient ssh, String ip, int port, HostKeyVerifier hostKeyVerifier, String user,
String privateKeyString, Stack stack) throws CloudbreakException, IOException {
ssh.addHostKeyVerifier(hostKeyVerifier);
ssh.connect(ip, port);
if (stack.getStackAuthentication().passwordAuthenticationRequired()) {
ssh.authPassword(user, stack.getStackAuthentication().getLoginPassword());
} else {
try {
KeyPair keyPair = KeyStoreUtil.createKeyPair(privateKeyString);
KeyPairWrapper keyPairWrapper = new KeyPairWrapper(keyPair);
ssh.authPublickey(user, keyPairWrapper);
} catch (Exception e) {
throw new CloudbreakException("Couldn't prepare SSH connection", e);
}
}
}
示例4: listFiles
import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper; //導入依賴的package包/類
@Test
public void listFiles() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
sftpHome.newFile("fred.txt");
List<RemoteResourceInfo> files;
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));
ssh.connect("localhost", subject.getPort());
try {
ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));
final SFTPClient sftp = ssh.newSFTPClient();
try {
files = sftp.ls("/");
} finally {
sftp.close();
}
} finally {
ssh.disconnect();
}
assertThat(files.size(), is(1));
assertThat(files.get(0).getName(), is("fred.txt"));
}
示例5: client
import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper; //導入依賴的package包/類
public SFTPClient client() throws IOException {
final SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(new PublicKeyVerifier(hostKey.publicKey()));
ssh.connect("localhost", port);
createdClients.add(ssh);
if (null == password) {
ssh.authPublickey(user, new KeyPairWrapper(keyPair));
} else {
ssh.authPassword(user, password);
}
return ssh.newSFTPClient();
}