12

I have a host that I can only access with sftp, scp, and rsync-- no ssh. I have a large tree of directories that I want to delete, but my sftp client apparently does not support recursive rms or rmdirs. In the help screen, it shows I can do recursive puts, but that doesn't help me.

How can I delete my files?

user394
  • 14,404
  • 21
  • 67
  • 93

2 Answers2

15

You can use the lftp client to do this. The the -r option to lftp rm recursively deletes directories and files.

$ lftp -u <user>,<pass> <server> 
lftp> rm -r <directory>

References

slm
  • 369,824
1

rsync has several delete options -

--delete            delete extraneous files from dest dirs
--delete-before     receiver deletes before xfer, not during
--delete-during     receiver deletes during the transfer
--delete-delay      find deletions during, delete after
--delete-after      receiver deletes after transfer, not during
--delete-excluded   also delete excluded files from dest dirs

any of these should remove files on your host once deleted from your local copy.

An example how to delete the content of an entire directory can be found here.

sambler
  • 366
  • rsync doesn't support sftp. Also, a concrete example might help to explain how to use these options better. – starbeamrainbowlabs Mar 12 '19 at 21:18
  • 3
    @starbeamrainbowlabs The question states I can only access with sftp, scp, and rsync - it isn't asking about only sftp. – sambler Mar 23 '19 at 03:35
  • That's kind of a weird way, but yeah, to empty a directory: mkdir a && rsync -r --delete a/ user@host:path. – x-yuri May 16 '22 at 18:03