3

I have a project where I need to remove non empty folders from an ftp server. I have tried with ftp.rmdir(), but I got an error message stating

Folder is not empty

I then tried just moving the directory with the ftp.rename() method, but I got the same error message there.

Does anyone know a good way to do this?

Peter Tretyakov
  • 3,380
  • 6
  • 38
  • 54
Kalimania
  • 31
  • 4

2 Answers2

0

You'll need to delete all the files in that directory first using mdelete

mdelete folder_name/*

then you should be able to remove the directory using rmdir

rmdir folder_name

Source

Community
  • 1
  • 1
vveleva
  • 46
  • 3
0

Apparently, FTP requires you to remove all files recursively.

Hers is a good example of how one can do:

https://github.com/dsabanin/BetterFTP

def rm_r(path)
 return if @deleted_paths_cache.include?(path)
 @deleted_paths_cache << path
 if directory?(path) 
  chdir path

  begin
    files = nlst
    files.each {|file| rm_r "#{path}/#{file}"}
  rescue Net::FTPTempError
    # maybe all files were deleted already
  end

  rmdir path
else
  rm(path)
end

end

Kalimania
  • 31
  • 4