1

Does anybody know how to remove remote directory via sftp? sftp doesn't support "rm -r" only "rm", so the only way I see is to save remote folder tree in a file with "rm" prefix and then execute sftp -b file And as sftp doesn't support "ls -lR" either I have to use "ls -l" in the loop to create such a file.

Is there an easier way? Thanks in advance.

Nick
  • 820
  • 2
  • 14
  • 29
  • Try, lftp. If you want to remove the directory `foo` and all its subfolders `rm -r foo` should work. – cic May 22 '14 at 09:23

3 Answers3

1

http://linux.about.com/od/commands/l/blcmdl1_sftp.htm shows that you can use rmdir

see the answer at https://superuser.com/questions/595401/why-is-sftp-rmdir-not-working

direct quote from Chris:

In my experience, rmdir prefers to work on an empty directory. If you're trying to delete the directory foo, I would do:

$rm foo/*
$rmdir foo
Community
  • 1
  • 1
Stuart
  • 1,733
  • 4
  • 21
  • 34
  • Note however that your updated answer does not work if you have files/directories in the directories in the `foo` directory. (I.e., it's not a general solution.) – cic May 22 '14 at 09:21
1

Would del -s do what you're looking to do?

djdy
  • 6,779
  • 6
  • 38
  • 62
1

rm -r seems to work fine for recursively removing a remote directory with files in it.

$ sftp --version
sftp: SSH Tectia Client 6.0.2 on sparc-sun-solaris2.8
Build: 84
Product: SSH Tectia Client
License type: commercial
SFT API: 2.0.3 (build 6.0.2.84)
Raihan
  • 10,095
  • 5
  • 27
  • 45