In my springboot application, i am transferring a file to sftp. I want to authenticate it only with username and password. However my java code still looking for private key to send, and i am getting the bellow error. How can i solve the below error. What changes do i need in the java class?
Caused by: org.apache.commons.vfs2.FileSystemException: Could not load private key from "/Users/123456/.ssh/id_rsa".
Caused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@180bc464
here is my code:
StandardFileSystemManager manager = new StandardFileSystemManager();
String serverAddress = "test.rebex.net";
String userId = "demo";
String password = "password";
String remoteDirectory = "/IN";
String filepath = "/Users/1234/Documents/TestNotes.txt";
File file = new File(filepath);
manager.init();
FileSystemOptions opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);
String sftpUri = "sftp://" + userId + ":" + password + "@" + serverAddress + "/" + remoteDirectory + filepath;
FileObject localFile = manager.resolveFile(file.getAbsolutePath());
FileObject remoteFile = manager.resolveFile(sftpUri, opts);
remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);
System.out.println("File upload successful");