Ad
How To Delete All Txt Files Inside An FTP Directory?
My app stores txt files on a FTP server which are also hosted on webservice.
In the directory where I host txt files I can find other txt files. I would like to delete all files in current directory every time when I store the new ones.
Actually i was trying to use the following command:
FTPClient ftpClient = new FTPClient();
ftpClient.connect(siteFTP);
if (ftpClient.login(usrFTP, pswFTP)) {
ftpClient.enterLocalPassiveMode();
FTPFile[] remoteFiles = ftpClient.listFiles(path);
if (remoteFiles.length > 0) {
ftpClient.deleteFile("/prenotazioni/*.txt");
}
}
But even if there was txt files in that directory, FTP respose is:
> DELE /prenotazioni/*.txt
> 550 File not found
Ad
Answer
Using *
won't work. After You get list of files in declared directory, You must iterate it and delete files one by one by using deleteFile(String pathname)
(also checking if file name endsWith(".txt")
).
Every FTPFile
has method getName()
. You should construct full path so FTPClient
will know what file to delete. I believe it would be something like:
ftpClient.deleteFile("/prenotazioni/" + remoteFiles[i].getName());
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad