Hi!
How could I create/delete a directory on the remote machine using FTPClient of org.apache.commons.net.ftp.*; ?
The code used to save a file on the remote machine is shown below. But I would like to update it for creating/deleting directories.
Thanks!
private void saveAttachedFileToRemoteMachine(String pathToFile, DefaultMutableTreeNode selectedNode) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect(this.url);
client.login(this.login,this.password);
client.setFileType(FTP.BINARY_FILE_TYPE);
String directoryName = new String();
Object elements[] = selectedNode.getPath();
for (int i = 0, n = elements.length; i < n; i++) {
directoryName = directoryName + elements[i] + "\\";
}
String filename = directoryName + text4.getText();
fis = new FileInputStream(pathToFile);
client.storeFile(filename, fis);
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}