http://blog.csdn.net/allen_zhao_2012/article/details/7941631
Http://www.cnblogs.com/longyg/archive/2012/06/25/2556576.html
http://xpenxpen.iteye.com/blog/2061869
http://blog.csdn.net/fyqcdbdx/article/details/23863793
Http://blog.csdn.net/u013256816/article/details/52701563?utm_source=gold_browser_extension
SFTP is the abbreviation for Secure File Transfer protocol, security File Transfer Protocol. You can provide a secure encryption method for transferring files. SFTP is a part of SSH and is a secure way to transfer files to the server. SFTP is the use of encrypted transmission of authentication information and transmitted data, so the use of SFTP is very safe. However, because this transmission uses the encryption/decryption technology, the transfer efficiency is much lower than the normal FTP, and if you have higher network security requirements, you can use SFTP instead of FTP.
The Channelsftp class is the Jsch implementation of the SFTP core class, which contains all of the sftp methods, such as: Put (): File Upload get (): File download CD (): Enter the specified directory ls (): Get a list of files in the specified directory Renam E (): Rename the specified file or directory rm (): Delete the specified file mkdir (): Create Directory RmDir (): Delete directory and so on (here omit the method parameters, put and get have multiple overloaded methods, see the source code, not listed here. )
A simple Jsch link to Linux and execute the utils of the command.
- Import Java.io.BufferedReader;
- Import java.io.IOException;
- Import Java.io.InputStream;
- Import Java.io.InputStreamReader;
- Import Com.jcraft.jsch.Channel;
- Import com.jcraft.jsch.ChannelExec;
- Import Com.jcraft.jsch.JSch;
- Import com.jcraft.jsch.JSchException;
- Import com.jcraft.jsch.Session;
- Public class Shellutils {
- private static Jsch Jsch;
- private static session session;
- /**
- * Connect to the specified IP
- *
- * @throws jschexception
- */
- public static void Connect (string user, String passwd, string host) throws jschexception {
- Jsch = new Jsch ();
- Session = jsch.getsession (user, host, 22);
- Session.setpassword (passwd);
- java.util.Properties config = new java.util.Properties ();
- Config.put ("stricthostkeychecking", "no");
- Session.setconfig (config);
- Session.connect ();
- }
- /**
- * Execution of RELATED commands
- * @throws jschexception
- */
- public static void ExecCmd (String command, string user, String passwd, string host) throws Jschexception {
- Connect (user, passwd, host);
- BufferedReader reader = null;
- Channel channel = null;
- try {
- While (Command! = null) {
- Channel = Session.openchannel ("exec");
- ((channelexec) channel). SetCommand (command);
- Channel.setinputstream (null);
- ((channelexec) channel). Seterrstream (System.err);
- Channel.connect ();
- InputStream in = Channel.getinputstream ();
- reader = new BufferedReader (new InputStreamReader (in));
- String buf = null;
- While ((buf = Reader.readline ()) = null) {
- System.out.println (BUF);
- }
- }
- } catch (IOException e) {
- E.printstacktrace ();
- } catch (Jschexception e) {
- E.printstacktrace ();
- } finally {
- try {
- Reader.close ();
- } catch (IOException e) {
- E.printstacktrace ();
- }
- Channel.disconnect ();
- Session.disconnect ();
- }
- }
- }
Com.jcraft.jsch.ChannelSftp explained in Java