3

I would like to recursively delete a folder and his subfolders. I use ncftp. This application provides rm and rmdir.

I already looked up the manpage, but it doesn't help.

djsmiley2kStaysInside
  • 6,943
  • 2
  • 36
  • 48
Peter
  • 1,095

3 Answers3

4

You need to use /*, as in rm -rf directory/*

Burgi
  • 6,768
2

This is how it works:

rm -rf directory

As someone pointed out, depending on the ncftp version it won't work. Try this syntax then:

rm -rf directory/*
Peter
  • 1,095
0

The accepted answer did not work for me and the documentation of ncftp states that -rf has no impact in ncftp (see below) i used the recurisve directory listing to retrive all file paths and delete them one by one.

#!/bin/bash
echo "Clearing files in FTP_FOLDER on FTP server..."
ncftpls -u "$FTP_USER" -p "$FTP_PASS" -R "ftp://$FTP_SERVER$FTP_FOLDER" > recursiveListing.txt
# exclude files
sed -i <matchForFilesToRemove> recursiveListing.txt

parse file and directory paths from recursiveListing.txt

dirPath="" declare -a filePaths while IFS= read -r line; do if [[ "${line: -1}" == ":" ]]; then dirPath="${line%:}" filePaths+=("rmdir $dirPath") continue fi if [[ -z "$line" ]]; then continue fi if [[ "$line" =~ .$ || "$line" =~ ..$ ]]; then continue fi fileName="${line##* }" filePath="$dirPath/$fileName" filePaths+=("rm $filePath") echo "$filePath" done < recursiveListing.txt rm recursiveListing.txt

for (( i=${#filePaths[@]}; i>=0; i-- )); do echo "${filePaths[$i]}" done > remCommands.txt

execute commands to clear ftp server

ncftp -u $FTP_USER -p $FTP_PASS $FTP_SERVER < remCommands.txt

As the Documentation sates:

rm: If you need to delete a remote file you can try the rm command. Much of the time this won't work because you won't have the proper access permissions. This command doesn't accept any flags, so you can't nuke a whole tree by using ``-rf'' flags like you can on UNIX (documentation).