SshClient ssh = new SshClient(); ssh.connect(host, port); //Authenticate PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient(); passwordAuthenticationClient.setUsername(userName); passwordAuthenticationClient.setPassword(password); int result = ssh.authenticate(passwordAuthenticationClient); if(result != AuthenticationProtocolState.COMPLETE){ throw new SFTPException("Login to " + host + ":" + port + " " + userName + "/" + password + " failed"); } //Open the SFTP channel SftpClient client = ssh.openSftpClient(); //Send the file client.put(filePath); //disconnect client.quit(); ssh.disconnect();
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(String publicKeyOpenSSH, String fingerprint) { return publicKeyHasFingerprint(publicKeySpecFromOpenSSH(publicKeyOpenSSH), fingerprint); }
private ExecResponse refresh(CommandUsingClient commandUsingClient) { return commandUsingClient.client.exec(commandUsingClient.command); }
SshClient ssh = = new SshClient(); ssh.connect(server, port, new IgnoreHostKeyVerification()); PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); pwd.setUsername(uid); pwd.setPassword(password); int result = ssh.authenticate(pwd); if (result == AuthenticationProtocolState.COMPLETE) { SessionChannelClient session = ssh.openSessionChannel(); session.executeCommand("sh test.sh"); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPublicKey(String publicKeyOpenSSH) { RSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH); return fingerprint(publicKeySpec.getPublicExponent(), publicKeySpec.getModulus()); }
@Override public Map<String, String> get() { return SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom); } }
/** * @return true if the keypair has the same SHA1 fingerprint as supplied */ public static boolean privateKeyHasSha1(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return sha1(privateKey).equals(fingerprint); }
private ExecResponse refresh(CommandUsingClient commandUsingClient) { return commandUsingClient.client.exec(commandUsingClient.command); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPublicKey(String publicKeyOpenSSH) { RSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH); return fingerprint(publicKeySpec.getPublicExponent(), publicKeySpec.getModulus()); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(String publicKeyOpenSSH, String fingerprint) { return publicKeyHasFingerprint(publicKeySpecFromOpenSSH(publicKeyOpenSSH), fingerprint); }
@Override public Map<String, String> get() { return SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom); } }
/** * @return true if the keypair has the same SHA1 fingerprint as supplied */ public static boolean privateKeyHasSha1(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return sha1(privateKey).equals(fingerprint); }
private ExecResponse refresh(CommandUsingClient commandUsingClient) { return commandUsingClient.client.exec(commandUsingClient.command); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(String publicKeyOpenSSH, String fingerprint) { return publicKeyHasFingerprint(publicKeySpecFromOpenSSH(publicKeyOpenSSH), fingerprint); }
/** * @return true if the keypair has the same SHA1 fingerprint as supplied */ public static boolean privateKeyHasSha1(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return sha1(privateKey).equals(fingerprint); }
private ExecResponse refresh(CommandUsingClient commandUsingClient) { return commandUsingClient.client.exec(commandUsingClient.command); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(String publicKeyOpenSSH, String fingerprint) { return publicKeyHasFingerprint(publicKeySpecFromOpenSSH(publicKeyOpenSSH), fingerprint); }
@Override public ExecResponse call() { ExecResponse response = client.exec("hostname"); //System.out.println("completed (concurrently) "+count.incrementAndGet()); return response; } }));
@Override public ExecResponse call() { ExecResponse response = client.exec("hostname"); //System.out.println("completed (concurrently) " + count.incrementAndGet()); return response; } }));