作为SFTP客户端, 如果使用秘钥的方式, 需要客户端产生公钥, 将公钥给服务端, 服务端配置在服务上.
如果是使用密码认证, 则服务端需要提供给客户用户名和密码.
密码的认证方式, java上传文件代码为:
private static void uploadSFTPFile(@NonNull String fileName) throws Throwable {
Connection sshConnection = new Connection("ipaddress", 22);
sshConnection.connect();
sshConnection.authenticateWithPassword("xxx", "xxxxx");
SFTPv3Client sftp = new SFTPv3Client(sshConnection);
// String localFile = "./"+fileName;
String localFile = fileName;
String remoteFileName = fileName.substring(fileName.lastIndexOf("\")+1);
String remoteFile = "/eeeee/xxxx/rrrrr/"+remoteFileName;
upload(sftp, localFile, remoteFile);
logger.info("Upload file {} to Geda success.", fileName);
sftp.close();
}
reference document:
sftp上传:密码认证和密钥认证两种方式_Emine-CSDN博客_sftp 密钥认证方式SSH远程管理 和服务的两种验证方式 SFTP_hotshortgg的博客-CSDN博客



