sftp - how to connect to winscp with username and ppk file from java program -


i have generate , put files on winscp using java program. connecting box (with winscp), use following credentials: host name: username: port: private key file:

i searched through how retrieve file server via sftp? , found below code:

import com.jcraft.jsch.*; public class testjsch  {     public static void main(string args[]) {         jsch jsch = new jsch();         session session = null;`enter code here`         try {             session = jsch.getsession("username", "127.0.0.1", 22);             session.setconfig("stricthostkeychecking", "no");             session.setpassword("password");             session.connect();              channel channel = session.openchannel("sftp");             channel.connect();             channelsftp sftpchannel = (channelsftp) channel;             sftpchannel.get("remotefile.txt", "localfile.txt");             sftpchannel.exit();             session.disconnect();         } catch (jschexception e) {             e.printstacktrace();           } catch (sftpexception e) {             e.printstacktrace();         }     } } 

all these codes using password whereas don't have password private key file.can me know how can connect server using private key file only?


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -