This snippet describes how to use j2ssh API to transfer files securely
Three jar files that is required to make it work are,
Three jar files that is required to make it work are,
- jce-jdk13-119.jar
- j2ssh-core-0.2.9.jar
- j2ssh-common-0.2.9.jar
import com.sshtools.j2ssh.SftpClient; import com.sshtools.j2ssh.SshClient; import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient; import com.sshtools.j2ssh.authentication.AuthenticationProtocolState; import com.sshtools.j2ssh.transport.IgnoreHostKeyVerification; sshClnt.connect("sftpServerName",new IgnoreHostKeyVerification()); PasswordAuthenticationClient pac = new PasswordAuthenticationClient(); pac.setUsername("username"); pac.setPassword("password"); int result = sshClnt.authenticate(pac); if (result == AuthenticationProtocolState.COMPLETE) { SftpClient sftp = sshClnt.openSftpClient(); sftp.lcd("/root/sourcePath"); sftp.cd("/root/destinationPath"); sftp.put("fileName"); sftp.quit(); sshClnt.disconnect(); }