Hello everyone
I have created a java program using jsch0.1.50.jar to remove the directories in the sftp server. But I could not remove the folder "03-03-2014" as it contains a subfolder named "1837hrs" when I try to run the program I am getting the following error:

4: The directory is not empty.
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2833)
at com.jcraft.jsch.ChannelSftp.rmdir(ChannelSftp.java:2109)
at SFTPrmdirinJava.main(SFTPrmdirinJava.java:40)
So how do I remove all the directories and the subdirectories all at once, is this possible ? Please check my code:

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class SFTPrmdirinJava {        
    * @param args
    public static void main(String[] args) {
        String SFTPHOST = "localhost";
        int    SFTPPORT = 22;
        String SFTPUSER = "Administrator";
        String SFTPPASS = "Password Changed";
        String SFTPWORKINGDIR = "SCPDemo/";
        String Dirname = "03-03-2014";                 
        Session     session     = null;
        Channel     channel     = null;
        ChannelSftp channelSftp = null;         
        try {           
            JSch jsch = new JSch();
            session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            channel = session.openChannel("sftp");
            channelSftp = (ChannelSftp)channel;
            System.out.println("The directory "+Dirname+" removed successfully");
        }catch(Exception ex){

PS: I am using windows server 2003 and using Bitwise ssh server which runs on port no 22.

traverse the directory and remove all sub directories, and all sub directories of the sub directories, etc, a recursive method will suffice.

This article has been dead for over six months. Start a new discussion instead.