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?

2 Answers 2

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

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.

3
  • rsync doesn't support sftp. Also, a concrete example might help to explain how to use these options better. Mar 12, 2019 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, 2019 at 3: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, 2022 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .