1, establish the connection
Connection con = new Connection (IP, PORT); You can not enter a port number
Connection
Con.connect (); This step must not forget
User name password for remote server
boolean isauthed = Con.authenticatewithpassword (Remoteuser,remotepass);
Establish an SCP client
Scpclient scpclient = Con.createscpclient ();
Server-side files are downloaded to the local directory
Scpclient.get ("/home/test/11.txt", "c:/");
Upload the local file to the server-side directory
Scp.put ("C:/12.txt", "/home/test");
To establish a session, only one Linux command can be executed within a session
Session session = NULL;
Session = Con.opensession ();
Use sessions to manipulate remote servers
For example: Delete files in a remote directory
Session.execcommand ("Rm-f". Concat (RemotePath). Concat (Qrcodefilemode));
Displays information after the command is executed
InputStream stdout = new Streamgobbler (Session.getstdout ());
BufferedReader br = new BufferedReader (new InputStreamReader (stdout));
while (true) {
String line = Br.readline ();
if (line = = null) {
Log.info ("Remote server return information: null");
Break
}
Log.info ("Remote Server return information:" + line);
}
Get launch status
System.out.println ("ExitCode:" + session.getexitstatus ());
Session.close ();
Con.close ();
PS: It is regrettable that the entire folder cannot be uploaded.