最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

【规避解决】sftp中rmdir出错:Couldn’t remove directory: Failure

sftp crifan 708浏览 0评论

折腾:

【已解决】命令行中ftp操作上传到远程服务器crifan.com

期间,想要删除文件夹,看了命令去用rmdir,结果还是不行:

sftp> rmdir http_restful_api

Couldn’t remove directory: Failure

sftp> pwd

Remote working directory: /home/wwwroot/book.crifan.com/books

sftp> ls -la

drwxr-xr-x    4 root     root         4096 Dec 14 14:44 .

drwxr-xr-x    5 www      www          4096 Dec  6 16:19 ..

drwxr-xr-x    6 root     root         4096 Dec 19 22:43 http_restful_api

drwxr-xr-x    6 root     root         4096 Dec  7 09:06 http_summary

sftp> rmdir http_restful_api

Couldn’t remove directory: Failure

搜:

sftp rmdir Couldn’t remove directory: Failure

linux – why is sftp rmdir not working? – Super User

先要删除文件夹下所有文件,成为空文件夹,然后rmdir才能删除

结果郁闷了,因为想要删除文件夹中内容,结果子文件夹也非空,无法删除:

sftp> cd /home/wwwroot/book.crifan.com/books/http_restful_api

sftp> pwd

Remote working directory: /home/wwwroot/book.crifan.com/books/http_restful_api

sftp> ls -la

drwxr-xr-x    6 root     root         4096 Dec 19 22:43 .

drwxr-xr-x    4 root     root         4096 Dec 14 14:44 ..

drwxr-xr-x    2 root     root         4096 Dec 14 14:38 epub

-rw-r–r–    1 root     root     26033916 Dec 19 22:45 http_restful_api.zip

drwxr-xr-x    2 root     root         4096 Dec 14 14:38 mobi

drwxr-xr-x    2 root     root         4096 Dec 14 14:38 pdf

drwxr-xr-x   10 root     root         4096 Dec 14 14:38 website

sftp> rm /home/wwwroot/book.crifan.com/books/http_restful_api/*

Removing /home/wwwroot/book.crifan.com/books/http_restful_api/epub

Couldn’t delete file: Failure

Removing /home/wwwroot/book.crifan.com/books/http_restful_api/http_restful_api.zip

Removing /home/wwwroot/book.crifan.com/books/http_restful_api/mobi

Couldn’t delete file: Failure

Removing /home/wwwroot/book.crifan.com/books/http_restful_api/pdf

Couldn’t delete file: Failure

Removing /home/wwwroot/book.crifan.com/books/http_restful_api/website

Couldn’t delete file: Failure

sftp> rm -r /home/wwwroot/book.crifan.com/books/http_restful_api

rm: Invalid flag -r

才发现别人说的:

because the -rf flag does not exist for rm in sftp.

Recursive remove directory using SFTP – codesd.com

说是可以mount远程路径到本地,然后再去删除

sftp delete folder recursively

python – Recursive remove directory using SFTP – Stack Overflow

通过python的paramiko去删除

recursive delete with sftp? – Unix & Linux Stack Exchange

也可以用lftp去删除

LFTP – sophisticated file transfer program

Recursively delete directory with JSch on SFTP with Java – larshaendler.com

How to delete folder recursively on remote server using SFTP in java?

#7813 (Deliting files recursively SFTP) – FileZilla

SFTP: Remove Non-Empty Directory? – Chilkat Forum

【总结】

sftp协议中,rm就不支持-r的递归删除。

rmdir只能删除空目录。

-》

如果想要递归删除非空目录,则:

  • 办法1:映射远端路径到本地,本地再用rm -rf递归删除(远端的路径)

  • 办法2:用lftp去递归删除

  • 办法3:(此处)直接用rsync实现文件同步的目的,就规避了sftp无法递归删除非空目录的问题

-》最终用rsync完成了本地文件同步到远程服务器的事情。很是方便。

转载请注明:在路上 » 【规避解决】sftp中rmdir出错:Couldn’t remove directory: Failure

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
14 queries in 0.195 seconds, using 10.11MB memory