0

One of my WordPress installs has been migrated recently and I'm trying to delete the directory of the old one but it's taken over 15 minutes to delete. It looks like it's deleting each individual file. Is this normal? Can it just do a folder delete and run itself in the background? For comparison, on Mac (Unix) it takes half a second.

2
  • 1
    Can it just do a folder delete and run itself in the background? - No.
    – Zoredache
    Commented Dec 19, 2015 at 1:19
  • 1
    SFTP directory deletion is a sequential series of recursive commands being executed from a remote location over a connection that has latency, one of the most inefficient ways of deleting files ever invented. Time to learn command line utilities and SSH terminal sessions. Commented Dec 19, 2015 at 6:35

3 Answers 3

2

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.

3

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 [email protected] "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 [email protected] "ls /home/user/directory" 
0
1

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.

You must log in to answer this question.

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