The previous article documented common file operations, where files are logged under the specified path of the Linux server through the SSH server.
Third-party jar packages are used here Jsch-0.1.53.jar
1. Delete all files (including this directory) under the specified path on the server-tested, run under Linux, no problem
1 /**2 * Delete3 *@paramDST4 *@paramSftputil5 *@return6 *@authorqin_hqing7 * @date July 6, 2015 PM 4:45:318 * @comment9 */Ten protected Static BooleanRemovefilefromssh (String DST, channelsftp chansftp) { One BooleanBL =false; A - Try { - chansftp.cd (DST); the@SuppressWarnings ("Unchecked") -Vector<lsentry> v =Chansftp.ls (DST); - if(v.size () = = 2) {//empty folder Delete directly - Chansftp.rmdir (DST); +}Else { - intDelsize = 0; + for(Iterator<lsentry> Iterator =v.iterator (); Iterator.hasnext ();) { A atLsentry Lsentry =(Lsentry) Iterator.next (); -String Ffname =lsentry.getfilename (); - if(Ffname.indexof (".") >0) {//file -CHANSFTP.RM (Ffname);//Deleting Files -}Else if(Ffname.indexof (".") = =-1) { -Removefilefromssh (dst+ffname+File.separator, chansftp); //If there is a problem with the path, try changing the file.separator to "/" . in chansftp.cd (DST); - } to + if(Delsize = = V.size ()-1) {//folder still exists under current folder - removefilefromssh (DST, chansftp); the } *Delsize + +; $ }Panax Notoginseng } - theBL =true; +}Catch(sftpexception e) { A e.printstacktrace (); the } + - returnBL; $}
2, upload-tomorrow in more;-)
Java common file Operations-2