1, Jsch development package downloadhttp://www.jcraft.com/jsch/Currently the latest version is: jsch-0.1.512, a simple example, listing the list of files in the specified directoryImport java.util.Properties;Import Java.util.Vector;Import com.jcraft.jsch.ChannelSftp;Import Com.jcraft.jsch.JSch;Import com.jcraft.jsch.Session;public class Demo003 {/*** @param args*
The previous article described the use of Jsch to achieve file upload function, this article mainly about the Jsch implementation of file download function. and introduce some auxiliary methods of SFTP, such as Cd,ls and so on.Similarly, Jsch file download also supports three modes of transmission: OVERWRITE, resume and Append, please refer to the previous essay:
Http://www.byywee.com/page/M0/S755/755589.htmlThis article only describes how to apply the SFTP functionality implemented by Jsch.SFTP is the abbreviation for secure file Transfer protocol, the Enron document transfer peace talks. The transfer file can be thought of as an encryption method of Enron. SFTP is part of SSH and is an Enron format for transferring files to the office. SFTP is the application of encrypted transmission of authentication information and transmission of data, so the appli
1. SFTP Credit Public key configuration1.1 Client-generated key pairTake the DSA Example:Ssh-keygen–t DSAAfter the command is executed, ID_DSA and id_dsa.pub two files are generated under the home/user name/.ssh directory1.2 willid_dsa.pubthe public key file is uploaded to the serverhome/User name/.sshdirectory underSCP id_dsa.pub username @ server-side ip:/home/user name/.sshYou also need to enter a password1.3 Adding a trusted public key to the serverLog on to the server, enter the/home/user n
(); } }); Sshd.setcommandfactory (scpcmdfactory); Sshd.start (); }2.JSch (Java Secure Channel)Jsch is also a pure Java implementation of SSH2. Dependent on the JavaTM Cryptography Extension (JCE). Jsch supports clients.Official website: http://www.jcraft.com/jsch/Example: http://www.jcr
The previous article described the use of Jsch to achieve file upload function, this article mainly about the Jsch implementation of file download function.and introduce some auxiliary methods of SFTP, such as Cd,ls and so on. Similarly, Jsch file download also supports three modes of transmission: OVERWRITE, resume and Append, please refer to the previous essay:
Use JSCH in Java to connect to a remote server and execute linux commands
Sometimes you may need to use code to control the execution of linux commands to implement some functions.
JSCH can be used to solve such problems. The specific code is as follows:
Public class CogradientImgFileManager {private static final Logger log = LoggerFactory. getLogger (CogradientImgFileManager. class); private static Channel
Background:
During the installation script, some database operations are performed, which can be performed only by the DBA account.
We use jsch to create an SSH channel and directly connect it to the target machine for execution. The effect is the same as opening the command line. The only special issue is the DBA password.
The Oracle (Oracle for our database) script provides the function of inputting the password together,! I'm afraid of everything!
Sometimes you might want to use code to control the execution of Linux commands to implement certain functions.
For this type of problem can be implemented using Jsch, the specific code is as follows:
public class cogradientimgfilemanager{private static final Logger log = Loggerfactory.getlogger (
Cogradientimgfilemanager.class);
private static channelexec channelexec;
private static Session session = NULL;
private static int timeout = 60000; T
Background: Some database operations are performed during the installation script, which can be performed only by the DBA account. We use JSCH to create an SSH channel and directly connect it to the target machine for execution. The effect is the same as opening the command line. The only special issue is the DBA password. Oracle (... SyntaxHighlighter. all (); Background: Some database operations are performed during the installation script, which ca
Sftpconstants. Java, which defines some parameter names we need:
public class SFTPConstants { public static final String SFTP_REQ_HOST = "host"; public static final String SFTP_REQ_PORT = "port"; public static final String SFTP_REQ_USERNAME = "username"; public static final String SFTP_REQ_PASSWORD = "password"; public static final int SFTP_DEFAULT_PORT = 22; public static final String SFTP_REQ_LOC = "location";}
Sftpchannel. Java we use it to obtain channel objects:
Import
1. Steps to establish a connection1), Jsch Jsch = new Jsch (); Create a Jsch object2), Session session = Jsch.getsession (userName, ip, port); Get a Session object based on username, host ip, Port3), Session.setpassword (password); Set Password4), Properties config = new properties ();Config.put ("stricthostkeychecking
Connecting to a remote database via Java JschSometimes our local code may not be able to connect to the database, because the database has added a whitelist, the IP server can connect to the database, but we can connect to the designated IP server, and then through the server to connect to the database, like many database visualization software. By using Jsch, we can also implement this functionality at the code level. Words do not say, directly open
A typical event was encountered in the recent project when Rhel's SELinux was set to disableUsing Java's Jsch library to invoke the SSH command will randomly return an empty string, the version I used is 0.1.49, and the latest version 0.1.51 is not tested.About jsch:http://www.jcraft.com/jsch/To this end, I specifically wrote a program test:Package Com.ibm.leo;import Com.ibm.gts.cms.common.guestssh.api.gues
File server with freesshd, file server configuration will not elaborate.Directly on the code, the code can be used directly. Importcom.jcraft.jsch.*;ImportJava.io.InputStream;Importjava.util.Properties;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;/** * @authorFC *@versionV1.0 * @Title sftpconnect * @Package Com.jsch * @Descript: TODO () * @date: 2018/8/30 pm 3:50*/ Public classSftpconnect {PrivateString User; PrivateString password; PrivateString host; Private intPort; Privatechannelsft
Use the JSCH framework to access other nodes through the jump machine.
Previously, I developed a code for Remotely accessing ssh for operations. Recently, a jump server is required to access the target service. After searching for a long time on the Internet and failing to find a good example, I read JSCH's API. But you can see it in the dark. Lenovo, does port forwarding map the target node ip: port to localhost: port, and then send a message through
exchange algorithms supported by OpenSSH and Jsch, one side is required to open the Exchange algorithm supported by the other.
OpenSSH enables only the following key exchange algorithms by default:-curve25519-sha256@libssh.org-ecdh-sha2-nistp256-ecdh-sha2-nistp384-ecdh-sha2-nistp521-diffie-hellman-group-exchange-sha256-DIFFIE-HELLMAN-GROUP14-SHA1
Where as Jsch claims to support this algorithms for key ex
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.