Hi!
I want to delete an empty directory from FTP Server, however my code works only for files. Let's say the root directory in my FTP Server is called as Documents
. I want to delete a directory Director
. Then I execute client.deleteFile("\\" + selectedPath);
, where selectedPath
is equal to Documents\Correspondence\Finance\Director
.
Why the directory Director
cannot be deleted? Thanks!
private void deleteFolderFromRemoteMachine(String selectedPath) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect(this.url);
client.login(this.login,this.password);
client.setFileType(FTP.BINARY_FILE_TYPE); // Tried also ASCII_FILE_TYPE
client.deleteFile("\\" + selectedPath);
client.logout();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot connect to the FTP server!", "Warning", JOptionPane.WARNING_MESSAGE);
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}