Jsch 深入浅出

http://xliangwu.iteye.com/blog/1499764



如果大家熟悉Linux的话,一定对ssh,sftp,scp等命令非常熟悉。ssh是一个安全协议,用来在不同系统或者服务器之间进行安全连接。ssh 在连接和传送的过程中会加密所有的数据。具体的解释,大家可以参考百度百科的文档。地址为:http://baike.baidu.com/view/16184.htm

但是SSH一般是基于客户端的或者Linux命令行的。比如客户端的工具:OpenSSH,putty,SSH Tectia;在linux上大家可以通过ssh username@host连接到所要想连接的主机。但是如果在J2EE中,如何实现SSH呢?进而可以实现SCP,SFTP的功能呢?下面介绍的JSCH就可以实现下边的功能。

JSCH是一个纯粹的用java实现SSH功能的java  library. 官方地址为:http://www.jcraft.com/jsch/

GitHub 地址为:https://github.com/vngx/vngx-jsch

mvn 配置如下:

<dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.46</version></dependency>

 

下面简单介绍下JSCH的特点:

1.基于DSA和RSA加密。

2.可以实现4中认证机制。分别是:

(1i): password

(2i): publickey(DSA,RSA)

(3i): keyboard-interactive

(4i): gss-api-with-mic

3.生成public/private key pair.

4.执行bash script 等脚本

5.可以通过HTTP/SOCK5 proxy

6.支持常见SSH1协议和SSH2协议

我们日常用到的JSCH主要是基于是密码认证和private key 认证。

基于密码认证的比较简单。简单代码如下:

 

 

Java代码   收藏代码
  1. public class JschHandler {  
  2.     private static final Logger log = LoggerFactory.getLogger(JschHandler.class);  
  3.       
  4.     public static final String SFTP_PROTOCAL = "sftp";  
  5.     private String username;  
  6.     private String host;  
  7.     private int port;  
  8.     private String identity;  
  9.     private UserInfo userInfo;  
  10.       
  11.     private JSch jsch = null;  
  12.     protected Session session = null;  
  13.     private boolean firstInit = false;  
  14.     private int authType = -1;  
  15.       
  16.     /** 
  17.      * Private/public key authorization 
  18.      * @param username user account 
  19.      * @param host  server host 
  20.      * @param port  ssh port 
  21.      * @param identity the path of private key file. 
  22.      * @see http://www.jcraft.com/jsch/ 
  23.      */  
  24.     public JschHandler(String username,String host,int port,String identity){  
  25.         this.username = username;  
  26.         this.host = host;  
  27.         this.port = port;  
  28.         this.identity = identity;  
  29.           
  30.         firstInit = false;  
  31.         jsch = new JSch();  
  32.           
  33.         authType = 0 ;  
  34.     }  
  35.       
  36.     /** 
  37.      * Password authorization 
  38.      * @param username 
  39.      * @param host 
  40.      * @param port 
  41.      * @param userInfo User information for authorization 
  42.      * @see com.jcraft.jsch.UserInfo 
  43.      * @see http://www.jcraft.com/jsch/ 
  44.      */  
  45.     public JschHandler(String username,String host,int port,UserInfo userInfo){  
  46.         this.username = username;  
  47.         this.host = host;  
  48.         this.port = port;  
  49.         this.userInfo = userInfo;  
  50.           
  51.         firstInit = false;  
  52.         jsch = new JSch();  
  53.         authType = 1;  
  54.     }  
  55.     /** 
  56.      *  
  57.      * Initialize SSH session. 
  58.      * When the parameters is not right, It will throw an JSchException. 
  59.      * @throws MessageServicerException 
  60.      * @see com.jcraft.jsch.JSch 
  61.      */  
  62.     @SuppressWarnings("static-access")  
  63.     protected void init() throws JSchException{  
  64.         try {  
  65.             validate();  
  66.             log.info("JSCH identity:"+identity);  
  67.             jsch.setLogger(new JschLogger());  
  68.             jsch.setConfig("StrictHostKeyChecking""no");  
  69.               
  70.             if(authType==0) jsch.addIdentity(identity);  
  71.             session = jsch.getSession(username, host, port);  
  72.               
  73.             if(authType==1) session.setUserInfo(userInfo);  
  74.             session.connect();  
  75.               
  76.             log.info("JSCH session connect success.");  
  77.         } catch (JSchException e) {  
  78.             log.error(e.getMessage());  
  79.             throw e;  
  80.         }  
  81.     }  
  82.       
  83.     /** 
  84.      * Validate parameters 
  85.      * @throws JSchException 
  86.      */  
  87.     private void validate() throws JSchException{  
  88.         if(firstInit) return;  
  89.         if(username==null||username.isEmpty()){  
  90.             throw new JSchException("Parameter:username is empty.");  
  91.         }  
  92.         if(host==null||host.isEmpty()){  
  93.             throw new JSchException("Parameter:host is empty.");  
  94.         }else{  
  95.             try {  
  96.                 InetAddress inet = InetAddress.getByName(host);  
  97.                 host = inet.getHostAddress();  
  98.                 log.info("JSCH connection address:"+host);  
  99.             } catch (UnknownHostException e) {  
  100.                 throw new JSchException(e.getMessage(),e);  
  101.             }  
  102.         }  
  103.           
  104.         if(authType==0&&(identity==null||identity.isEmpty())){  
  105.             throw new JSchException("Parameter:identity is empty.");  
  106.         }  
  107.           
  108.         if(authType==1&&(userInfo==null)){  
  109.             throw new JSchException("Parameter:userInfo is empty.");  
  110.         }  
  111.           
  112.         firstInit = true;  
  113.     }  
  114.       
  115.     /** 
  116.      * release connections. 
  117.      * @author  
  118.      */  
  119.     protected void destory(){  
  120.         if(session!=null) session.disconnect();  
  121.         log.info("JSCH session destory");  
  122.     }  
  123.     private static class JschLogger implements com.jcraft.jsch.Logger{  
  124.   
  125.         @Override  
  126.         public boolean isEnabled(int level) {  
  127.             return true;  
  128.         }  
  129.   
  130.         @Override  
  131.         public void log(int level, String message) {  
  132.             System.out.println(String.format("[JSCH --> %s]", message));  
  133.         }  
  134.     }  
  135.       
  136.     public void setUserInfo(UserInfo userInfo) {  
  137.         this.userInfo = userInfo;  
  138.     }  
  139. }  

    client

 

Java代码   收藏代码
  1. public static class MyUserInfo implements UserInfo, UIKeyboardInteractive {  
  2.         public String getPassword() {  
  3.             return null;  
  4.         }  
  5.   
  6.         public boolean promptYesNo(String str) {  
  7.             Object[] options = { "yes""no" };  
  8.             int foo = JOptionPane.showOptionDialog(null, str, "Warning",  
  9.                     JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,  
  10.                     null, options, options[0]);  
  11.             return foo == 0;  
  12.         }  
  13.   
  14.         String passphrase;  
  15.         JTextField passphraseField = (JTextField) new JPasswordField(20);  
  16.   
  17.         public String getPassphrase() {  
  18.             return passphrase;  
  19.         }  
  20.   
  21.         public boolean promptPassphrase(String message) {  
  22.             Object[] ob = { passphraseField };  
  23.             int result = JOptionPane.showConfirmDialog(null, ob, message,  
  24.                     JOptionPane.OK_CANCEL_OPTION);  
  25.             if (result == JOptionPane.OK_OPTION) {  
  26.                 passphrase = passphraseField.getText();  
  27.                 return true;  
  28.             } else {  
  29.                 return false;  
  30.             }  
  31.         }  
  32.   
  33.         public boolean promptPassword(String message) {  
  34.             return true;  
  35.         }  
  36.   
  37.         public void showMessage(String message) {  
  38.             JOptionPane.showMessageDialog(null, message);  
  39.         }  
  40.   
  41.         final GridBagConstraints gbc = new GridBagConstraints(001111,  
  42.                 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,  
  43.                 new Insets(0000), 00);  
  44.         private Container panel;  
  45.   
  46.         public String[] promptKeyboardInteractive(String destination,  
  47.                 String name, String instruction, String[] prompt, boolean[] echo) {  
  48.             panel = new JPanel();  
  49.             panel.setLayout(new GridBagLayout());  
  50.   
  51.             gbc.weightx = 1.0;  
  52.             gbc.gridwidth = GridBagConstraints.REMAINDER;  
  53.             gbc.gridx = 0;  
  54.             panel.add(new JLabel(instruction), gbc);  
  55.             gbc.gridy++;  
  56.   
  57.             gbc.gridwidth = GridBagConstraints.RELATIVE;  
  58.   
  59.             JTextField[] texts = new JTextField[prompt.length];  
  60.             for (int i = 0; i < prompt.length; i++) {  
  61.                 gbc.fill = GridBagConstraints.NONE;  
  62.                 gbc.gridx = 0;  
  63.                 gbc.weightx = 1;  
  64.                 panel.add(new JLabel(prompt[i]), gbc);  
  65.   
  66.                 gbc.gridx = 1;  
  67.                 gbc.fill = GridBagConstraints.HORIZONTAL;  
  68.                 gbc.weighty = 1;  
  69.                 if (echo[i]) {  
  70.                     texts[i] = new JTextField(20);  
  71.                 } else {  
  72.                     texts[i] = new JPasswordField(20);  
  73.                 }  
  74.                 panel.add(texts[i], gbc);  
  75.                 gbc.gridy++;  
  76.             }  
  77.   
  78.             if (JOptionPane.showConfirmDialog(null, panel, destination + ": "  
  79.                     + name, JOptionPane.OK_CANCEL_OPTION,  
  80.                     JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {  
  81.                 String[] response = new String[prompt.length];  
  82.                 for (int i = 0; i < prompt.length; i++) {  
  83.                     response[i] = texts[i].getText();  
  84.                 }  
  85.                 return response;  
  86.             } else {  
  87.                 return null// cancel  
  88.             }  
  89.         }  
  90.     }  

 @Test

Java代码   收藏代码
  1. public void testSftp() throws JSchException{  
  2.     UserInfo userInfo = new MyUserInfo();  
  3.     JftpHandler jhandler = new JftpHandler("username","hostname",22,userInfo);  
  4.     try {  
  5.         jhandler.init();  
  6.     } catch (Exception e) {  
  7.         // TODO Auto-generated catch block  
  8.         e.printStackTrace();  
  9.     }  
  10.     String pwd = null;  
  11.     try {  
  12.         pwd = jhandler.pwd();  
  13.     } catch (SftpException e) {  
  14.         // TODO Auto-generated catch block  
  15.         e.printStackTrace();  
  16.     }  
  17.     System.out.println(pwd);  
  18. /       jhandler.destory();  
  19. }  
 

基于private key 认证的有点费时。关于如何配置private/public key认证,大家通过google来配置。简单流程如下:

1.在linux 下执行ssh-keygen -t dsa /ssh-keygen -t rsa.这样就会成一对对应的public key 和private key.比如id_dsa_1024,id_dsa_1024.pub.

2. 把public key(id_dsa_1024.pub)复制到想要连接的服务器上,放到对应用户的.ssh目录下。

3.

cd ~/.ssh

#将Client的公钥放入Server的信任列表

cat id_dsa_1024.pub >> authorized_keys

#更新权限,很重要

chmod 0600 *从此以后Client SSH登录Server就不要手工输入密码了

配置完成以后,重新登录一下,就可以发现不用输入密码就可以实现远程登录了。

由于现在基于SSH协议的算法很多,加密和解密的算法也不一样。目前Jsch只支持OpenSSH和SSH 1生成的private/public key.

所以当你们发现不能通过private/public key认证的时候,不是jsch的问题,而是不能识别的问题。

简单代码如下:

 

 

 

Java代码   收藏代码
  1. @Test  
  2.     public void testSftp() throws JSchException{  
  3.         JftpHandler jhandler = new JftpHandler("username","hostname",22,"C:\\data\\id_dsa_2048_a");  
  4.         try {  
  5.             jhandler.init();  
  6.         } catch (Exception e) {  
  7.             // TODO Auto-generated catch block  
  8.             e.printStackTrace();  
  9.         }  
  10.         String pwd = null;  
  11.         try {  
  12.             pwd = jhandler.pwd();  
  13.         } catch (SftpException e) {  
  14.             // TODO Auto-generated catch block  
  15.             e.printStackTrace();  
  16.         }  
  17.         System.out.println(pwd);  
  18. //      jhandler.destory();  
  19.     }  

如果大家熟悉Linux的话,一定对ssh,sftp,scp等命令非常熟悉。ssh是一个安全协议,用来在不同系统或者服务器之间进行安全连接。ssh 在连接和传送的过程中会加密所有的数据。具体的解释,大家可以参考百度百科的文档。地址为:http://baike.baidu.com/view/16184.htm

但是SSH一般是基于客户端的或者Linux命令行的。比如客户端的工具:OpenSSH,putty,SSH Tectia;在linux上大家可以通过ssh username@host连接到所要想连接的主机。但是如果在J2EE中,如何实现SSH呢?进而可以实现SCP,SFTP的功能呢?下面介绍的JSCH就可以实现下边的功能。

JSCH是一个纯粹的用java实现SSH功能的java  library. 官方地址为:http://www.jcraft.com/jsch/

GitHub 地址为:https://github.com/vngx/vngx-jsch

mvn 配置如下:

<dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.46</version></dependency>

 

下面简单介绍下JSCH的特点:

1.基于DSA和RSA加密。

2.可以实现4中认证机制。分别是:

(1i): password

(2i): publickey(DSA,RSA)

(3i): keyboard-interactive

(4i): gss-api-with-mic

3.生成public/private key pair.

4.执行bash script 等脚本

5.可以通过HTTP/SOCK5 proxy

6.支持常见SSH1协议和SSH2协议

我们日常用到的JSCH主要是基于是密码认证和private key 认证。

基于密码认证的比较简单。简单代码如下:

 

 

Java代码   收藏代码
  1. public class JschHandler {  
  2.     private static final Logger log = LoggerFactory.getLogger(JschHandler.class);  
  3.       
  4.     public static final String SFTP_PROTOCAL = "sftp";  
  5.     private String username;  
  6.     private String host;  
  7.     private int port;  
  8.     private String identity;  
  9.     private UserInfo userInfo;  
  10.       
  11.     private JSch jsch = null;  
  12.     protected Session session = null;  
  13.     private boolean firstInit = false;  
  14.     private int authType = -1;  
  15.       
  16.     /** 
  17.      * Private/public key authorization 
  18.      * @param username user account 
  19.      * @param host  server host 
  20.      * @param port  ssh port 
  21.      * @param identity the path of private key file. 
  22.      * @see http://www.jcraft.com/jsch/ 
  23.      */  
  24.     public JschHandler(String username,String host,int port,String identity){  
  25.         this.username = username;  
  26.         this.host = host;  
  27.         this.port = port;  
  28.         this.identity = identity;  
  29.           
  30.         firstInit = false;  
  31.         jsch = new JSch();  
  32.           
  33.         authType = 0 ;  
  34.     }  
  35.       
  36.     /** 
  37.      * Password authorization 
  38.      * @param username 
  39.      * @param host 
  40.      * @param port 
  41.      * @param userInfo User information for authorization 
  42.      * @see com.jcraft.jsch.UserInfo 
  43.      * @see http://www.jcraft.com/jsch/ 
  44.      */  
  45.     public JschHandler(String username,String host,int port,UserInfo userInfo){  
  46.         this.username = username;  
  47.         this.host = host;  
  48.         this.port = port;  
  49.         this.userInfo = userInfo;  
  50.           
  51.         firstInit = false;  
  52.         jsch = new JSch();  
  53.         authType = 1;  
  54.     }  
  55.     /** 
  56.      *  
  57.      * Initialize SSH session. 
  58.      * When the parameters is not right, It will throw an JSchException. 
  59.      * @throws MessageServicerException 
  60.      * @see com.jcraft.jsch.JSch 
  61.      */  
  62.     @SuppressWarnings("static-access")  
  63.     protected void init() throws JSchException{  
  64.         try {  
  65.             validate();  
  66.             log.info("JSCH identity:"+identity);  
  67.             jsch.setLogger(new JschLogger());  
  68.             jsch.setConfig("StrictHostKeyChecking""no");  
  69.               
  70.             if(authType==0) jsch.addIdentity(identity);  
  71.             session = jsch.getSession(username, host, port);  
  72.               
  73.             if(authType==1) session.setUserInfo(userInfo);  
  74.             session.connect();  
  75.               
  76.             log.info("JSCH session connect success.");  
  77.         } catch (JSchException e) {  
  78.             log.error(e.getMessage());  
  79.             throw e;  
  80.         }  
  81.     }  
  82.       
  83.     /** 
  84.      * Validate parameters 
  85.      * @throws JSchException 
  86.      */  
  87.     private void validate() throws JSchException{  
  88.         if(firstInit) return;  
  89.         if(username==null||username.isEmpty()){  
  90.             throw new JSchException("Parameter:username is empty.");  
  91.         }  
  92.         if(host==null||host.isEmpty()){  
  93.             throw new JSchException("Parameter:host is empty.");  
  94.         }else{  
  95.             try {  
  96.                 InetAddress inet = InetAddress.getByName(host);  
  97.                 host = inet.getHostAddress();  
  98.                 log.info("JSCH connection address:"+host);  
  99.             } catch (UnknownHostException e) {  
  100.                 throw new JSchException(e.getMessage(),e);  
  101.             }  
  102.         }  
  103.           
  104.         if(authType==0&&(identity==null||identity.isEmpty())){  
  105.             throw new JSchException("Parameter:identity is empty.");  
  106.         }  
  107.           
  108.         if(authType==1&&(userInfo==null)){  
  109.             throw new JSchException("Parameter:userInfo is empty.");  
  110.         }  
  111.           
  112.         firstInit = true;  
  113.     }  
  114.       
  115.     /** 
  116.      * release connections. 
  117.      * @author  
  118.      */  
  119.     protected void destory(){  
  120.         if(session!=null) session.disconnect();  
  121.         log.info("JSCH session destory");  
  122.     }  
  123.     private static class JschLogger implements com.jcraft.jsch.Logger{  
  124.   
  125.         @Override  
  126.         public boolean isEnabled(int level) {  
  127.             return true;  
  128.         }  
  129.   
  130.         @Override  
  131.         public void log(int level, String message) {  
  132.             System.out.println(String.format("[JSCH --> %s]", message));  
  133.         }  
  134.     }  
  135.       
  136.     public void setUserInfo(UserInfo userInfo) {  
  137.         this.userInfo = userInfo;  
  138.     }  
  139. }  

    client

 

Java代码   收藏代码
  1. public static class MyUserInfo implements UserInfo, UIKeyboardInteractive {  
  2.         public String getPassword() {  
  3.             return null;  
  4.         }  
  5.   
  6.         public boolean promptYesNo(String str) {  
  7.             Object[] options = { "yes""no" };  
  8.             int foo = JOptionPane.showOptionDialog(null, str, "Warning",  
  9.                     JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,  
  10.                     null, options, options[0]);  
  11.             return foo == 0;  
  12.         }  
  13.   
  14.         String passphrase;  
  15.         JTextField passphraseField = (JTextField) new JPasswordField(20);  
  16.   
  17.         public String getPassphrase() {  
  18.             return passphrase;  
  19.         }  
  20.   
  21.         public boolean promptPassphrase(String message) {  
  22.             Object[] ob = { passphraseField };  
  23.             int result = JOptionPane.showConfirmDialog(null, ob, message,  
  24.                     JOptionPane.OK_CANCEL_OPTION);  
  25.             if (result == JOptionPane.OK_OPTION) {  
  26.                 passphrase = passphraseField.getText();  
  27.                 return true;  
  28.             } else {  
  29.                 return false;  
  30.             }  
  31.         }  
  32.   
  33.         public boolean promptPassword(String message) {  
  34.             return true;  
  35.         }  
  36.   
  37.         public void showMessage(String message) {  
  38.             JOptionPane.showMessageDialog(null, message);  
  39.         }  
  40.   
  41.         final GridBagConstraints gbc = new GridBagConstraints(001111,  
  42.                 GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,  
  43.                 new Insets(0000), 00);  
  44.         private Container panel;  
  45.   
  46.         public String[] promptKeyboardInteractive(String destination,  
  47.                 String name, String instruction, String[] prompt, boolean[] echo) {  
  48.             panel = new JPanel();  
  49.             panel.setLayout(new GridBagLayout());  
  50.   
  51.             gbc.weightx = 1.0;  
  52.             gbc.gridwidth = GridBagConstraints.REMAINDER;  
  53.             gbc.gridx = 0;  
  54.             panel.add(new JLabel(instruction), gbc);  
  55.             gbc.gridy++;  
  56.   
  57.             gbc.gridwidth = GridBagConstraints.RELATIVE;  
  58.   
  59.             JTextField[] texts = new JTextField[prompt.length];  
  60.             for (int i = 0; i < prompt.length; i++) {  
  61.                 gbc.fill = GridBagConstraints.NONE;  
  62.                 gbc.gridx = 0;  
  63.                 gbc.weightx = 1;  
  64.                 panel.add(new JLabel(prompt[i]), gbc);  
  65.   
  66.                 gbc.gridx = 1;  
  67.                 gbc.fill = GridBagConstraints.HORIZONTAL;  
  68.                 gbc.weighty = 1;  
  69.                 if (echo[i]) {  
  70.                     texts[i] = new JTextField(20);  
  71.                 } else {  
  72.                     texts[i] = new JPasswordField(20);  
  73.                 }  
  74.                 panel.add(texts[i], gbc);  
  75.                 gbc.gridy++;  
  76.             }  
  77.   
  78.             if (JOptionPane.showConfirmDialog(null, panel, destination + ": "  
  79.                     + name, JOptionPane.OK_CANCEL_OPTION,  
  80.                     JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {  
  81.                 String[] response = new String[prompt.length];  
  82.                 for (int i = 0; i < prompt.length; i++) {  
  83.                     response[i] = texts[i].getText();  
  84.                 }  
  85.                 return response;  
  86.             } else {  
  87.                 return null// cancel  
  88.             }  
  89.         }  
  90.     }  

 @Test

Java代码   收藏代码
  1. public void testSftp() throws JSchException{  
  2.     UserInfo userInfo = new MyUserInfo();  
  3.     JftpHandler jhandler = new JftpHandler("username","hostname",22,userInfo);  
  4.     try {  
  5.         jhandler.init();  
  6.     } catch (Exception e) {  
  7.         // TODO Auto-generated catch block  
  8.         e.printStackTrace();  
  9.     }  
  10.     String pwd = null;  
  11.     try {  
  12.         pwd = jhandler.pwd();  
  13.     } catch (SftpException e) {  
  14.         // TODO Auto-generated catch block  
  15.         e.printStackTrace();  
  16.     }  
  17.     System.out.println(pwd);  
  18. /       jhandler.destory();  
  19. }  
 

基于private key 认证的有点费时。关于如何配置private/public key认证,大家通过google来配置。简单流程如下:

1.在linux 下执行ssh-keygen -t dsa /ssh-keygen -t rsa.这样就会成一对对应的public key 和private key.比如id_dsa_1024,id_dsa_1024.pub.

2. 把public key(id_dsa_1024.pub)复制到想要连接的服务器上,放到对应用户的.ssh目录下。

3.

cd ~/.ssh

#将Client的公钥放入Server的信任列表

cat id_dsa_1024.pub >> authorized_keys

#更新权限,很重要

chmod 0600 *从此以后Client SSH登录Server就不要手工输入密码了

配置完成以后,重新登录一下,就可以发现不用输入密码就可以实现远程登录了。

由于现在基于SSH协议的算法很多,加密和解密的算法也不一样。目前Jsch只支持OpenSSH和SSH 1生成的private/public key.

所以当你们发现不能通过private/public key认证的时候,不是jsch的问题,而是不能识别的问题。

简单代码如下:

 

 

 

Java代码   收藏代码
  1. @Test  
  2.     public void testSftp() throws JSchException{  
  3.         JftpHandler jhandler = new JftpHandler("username","hostname",22,"C:\\data\\id_dsa_2048_a");  
  4.         try {  
  5.             jhandler.init();  
  6.         } catch (Exception e) {  
  7.             // TODO Auto-generated catch block  
  8.             e.printStackTrace();  
  9.         }  
  10.         String pwd = null;  
  11.         try {  
  12.             pwd = jhandler.pwd();  
  13.         } catch (SftpException e) {  
  14.             // TODO Auto-generated catch block  
  15.             e.printStackTrace();  
  16.         }  
  17.         System.out.println(pwd);  
  18. //      jhandler.destory();  
  19.     }  
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值