Почему удаление каталога занимает так много времени по SFTP?

651
1.21 gigawatts

Одна из моих установок WordPress была недавно перенесена, и я пытаюсь удалить каталог старой, но удаление заняло более 15 минут. Похоже, что он удаляет каждый отдельный файл. Это нормально? Может ли он просто удалить папку и запустить ее в фоновом режиме? Для сравнения, на Mac (Unix) это занимает полсекунды.

0
`Может ли он просто удалить папку и запустить ее в фоновом режиме?` - Нет. Zoredache 8 лет назад 1
Удаление каталога SFTP - это последовательная серия рекурсивных команд, выполняемых из удаленного местоположения по соединению с задержкой - один из самых неэффективных способов удаления файлов, когда-либо изобретенных. Время изучать утилиты командной строки и сеансы терминала SSH. Fiasco Labs 8 лет назад 1

3 ответа на вопрос

2
JakeGould

Can it just do a folder delete and run itself in the background? For comparison, on Mac (Unix) it takes half a second.

This is not just an SFTP issue but also a non-local (aka: networked) file system issue. When you are on your Mac—or any OS; just directly on the system—you have direct access to your file system. And since the filesystem is—really simplifying it but for clarity—just a small database/index with file/directory location pointers. So what happens when you delete a file or directory locally is that local file system database/index file is acted on fairly quickly since it is—of course—local.

In contrast, when accessing a file system remotely via a networking protocol such as SFTP, you don’t have direct access to the file system. So if you have to delete every file/directory via a network connection, first the network connection needs to get a list of files/directories from the remote file system. And the when the program gets that list, then it will run the remote action to remove a file. This method is quiet inefficient and which is why having some form of direct file system access is always preferred.

That said, if you have an SFTP account you should also have SSH access since an SFTP connection is typically just managed as an SSH subsystem. So if you are going nuts waiting for files/directories delete just login via SSH and run an rm -rf command on the files/directories in question.

1
user3201068

The secure file transfer protocol doesn't provide for direct access to the operating system's API.

This pretty much means no.

Deleting via SSH might be faster, if you have shell access.

1
jbrahy

Usually if you have sftp access you'll also have ssh access and you can execute remote commands using that. So to recursively remove a directory structure you would use the -r parameter to the rm command. i.e.

ssh user@hostname.com "rm -rf /home/user/directory" 

Be very careful with this command and be 100% of the directory you're deleting is the correct one. You can also list the contents of the directory to be sure by doing this.

ssh user@hostname.com "ls /home/user/directory" 
Я в целом согласен с тем, что вы описываете, и понимаю, как работает удаленное выполнение команд, но, честно говоря, сначала гораздо безопаснее просто подключиться к серверу по SSH и затем * запустить * команду `ls` или` rm -rf` с этой точки. JakeGould 8 лет назад 0