Rmdir and --delete-empty-src-dirs file does not exist


#1

Not sure if I am doing something wrong or rmdir is not supported with sftp remotes or if this is a bug. I have tried using rmdir and the --delete-empty-src-dirs flag with rclone move and get the same results on 2 different sftp servers as remotes. Also, I get the same results with or without a leading / in the path. Any help would be appreciated.

[centos@util-01 ~]$ rclone rmdir testsftp:testdir1/testdir2 --log-level DEBUG
2018/11/27 23:33:28 DEBUG : rclone: Version “v1.45” starting with parameters [“rclone” “rmdir” “testsftp:testdir1/testdir2” “–log-level” “DEBUG”]
2018/11/27 23:33:28 DEBUG : Using config file from “/home/centos/.config/rclone/rclone.conf”
2018/11/27 23:33:29 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1/testdir2: Removing directory
2018/11/27 23:33:29 ERROR : Attempt 1/3 failed with 1 errors and: file does not exist
2018/11/27 23:33:29 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1/testdir2: Removing directory
2018/11/27 23:33:29 ERROR : Attempt 2/3 failed with 1 errors and: file does not exist
2018/11/27 23:33:29 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1/testdir2: Removing directory
2018/11/27 23:33:29 ERROR : Attempt 3/3 failed with 1 errors and: file does not exist
2018/11/27 23:33:29 Failed to rmdir: file does not exist

[centos@util-01 ~]$ rclone rmdir testsftp:/testdir1/testdir2 --log-level DEBUG
2018/11/27 23:35:54 DEBUG : rclone: Version “v1.45” starting with parameters [“rclone” “rmdir” “testsftp:/testdir1/testdir2” “–log-level” “DEBUG”]
2018/11/27 23:35:54 DEBUG : Using config file from “/home/centos/.config/rclone/rclone.conf”
2018/11/27 23:35:54 DEBUG : sftp://rclonetest@sftp.example.com:2222//testdir1/testdir2: Removing directory
2018/11/27 23:35:54 ERROR : Attempt 1/3 failed with 1 errors and: file does not exist
2018/11/27 23:35:54 DEBUG : sftp://rclonetest@sftp.example.com:2222//testdir1/testdir2: Removing directory
2018/11/27 23:35:54 ERROR : Attempt 2/3 failed with 1 errors and: file does not exist
2018/11/27 23:35:54 DEBUG : sftp://rclonetest@sftp.example.com:2222//testdir1/testdir2: Removing directory
2018/11/27 23:35:54 ERROR : Attempt 3/3 failed with 1 errors and: file does not exist
2018/11/27 23:35:54 Failed to rmdir: file does not exist

[centos@util-01 ~]$ rclone lsd testsftp:/testdir1 --log-level DEBUG
2018/11/27 23:40:44 DEBUG : rclone: Version “v1.45” starting with parameters [“rclone” “lsd” “testsftp:/testdir1” “–log-level” “DEBUG”]
2018/11/27 23:40:44 DEBUG : Using config file from “/home/centos/.config/rclone/rclone.conf”
-1 2018-11-27 23:07:48 -1 testdir2
2018/11/27 23:40:44 DEBUG : 11 go routines active
2018/11/27 23:40:44 DEBUG : rclone: Version “v1.45” finishing with parameters [“rclone” “lsd” “testsftp:/testdir1” “–log-level” “DEBUG”]

[root@sftp01 ~]# ls -alh /home/rclonetest/testdir1/testdir2/
total 0
drwxr-xr-x. 2 root root 6 Nov 27 23:07 .
drwxr-xr-x. 3 root root 21 Nov 27 23:07 …


#2

It looks like you are trying to access files in the user’s home directory. So you want the syntax testsftp:dir without the leading /.

I’m not sure why exactly rmdir isn’t removing that directory.

What sftp server are you using?

Can you try with the latest beta too?


#3

The output from my test is connecting to an sftp server running crushftp. The other sftp server that I get the same results from is a vendors server, I have reached out but haven’t received a response yet. Using the latest beta version I am getting the same results.

[centos@util-01 ~]$ rclone rmdir testsftp:testdir1/testdir2 --log-level DEBUG
2018/11/28 16:16:14 DEBUG : rclone: Version “v1.45-006-geb412537-beta” starting with parameters [“rclone” “rmdir” “testsftp:testdir1/testdir2” “–log-level” “DEBUG”]
2018/11/28 16:16:14 DEBUG : Using config file from “/home/centos/.config/rclone/rclone.conf”
2018/11/28 16:16:14 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1/testdir2: Removing directory
2018/11/28 16:16:14 ERROR : Attempt 1/3 failed with 1 errors and: file does not exist
2018/11/28 16:16:14 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1/testdir2: Removing directory
2018/11/28 16:16:14 ERROR : Attempt 2/3 failed with 1 errors and: file does not exist
2018/11/28 16:16:14 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1/testdir2: Removing directory
2018/11/28 16:16:14 ERROR : Attempt 3/3 failed with 1 errors and: file does not exist
2018/11/28 16:16:14 Failed to rmdir: file does not exist


#4

Is there any chance you could give me temporary access to it? If so DM me!

Thanks


#5

I am unable to provide any external access but I can try any suggestions you may have. So far the only answer I have received from our vendor is the software they are using is running on a Windows server, still digging though. I did setup a test to a server running sftp with just OpenSSH and the rmdir worked as expected.

Here is some logging from our CrushFTP server when attempting to run an rclone rmdir.

MDTM|11/28/2018 20:21:19.299|[SFTP:8811356_0:rclonetest:xx.xx.xx.xx] READ: getFileAttributes /rclonetest/testdir1/testdir2
DELE|11/28/2018 20:21:19.302|[SFTP:8811356_0:rclonetest:xx.xx.xx.xx] READ: 550 DELE error:ÞLE-error%
SSH_SERVER|11/28/2018 20:21:19.302|pool-1-thread-51436
SSH_SERVER|11/28/2018 20:21:19.302|java.io.FileNotFoundException: ÞLE-error There is no file.%
SSH_SERVER|11/28/2018 20:21:19.302|crushftp.server.ServerSessionSSH.removeFile:1284
SSH_SERVER|11/28/2018 20:21:19.302|com.maverick.sshd.SftpSubsystem$RemoveFileOperation.doOperation:890
SSH_SERVER|11/28/2018 20:21:19.302|com.maverick.sshd.SftpSubsystem$FileSystemOperation.doTask:2467
SSH_SERVER|11/28/2018 20:21:19.302|com.maverick.sshd.ConnectionAwareTask.run:27
SSH_SERVER|11/28/2018 20:21:19.302|com.maverick.ssh.ExecutorOperationSupport$OperationTask.executeAllTasks:173
SSH_SERVER|11/28/2018 20:21:19.302|com.maverick.ssh.ExecutorOperationSupport$OperationTask.run:110
SSH_SERVER|11/28/2018 20:21:19.302|java.util.concurrent.Executors$RunnableAdapter.call:511
SSH_SERVER|11/28/2018 20:21:19.302|java.util.concurrent.FutureTask.run:266
SSH_SERVER|11/28/2018 20:21:19.302|java.util.concurrent.ThreadPoolExecutor.runWorker:1142
SSH_SERVER|11/28/2018 20:21:19.302|java.util.concurrent.ThreadPoolExecutor$Worker.run:617
SSH_SERVER|11/28/2018 20:21:19.302|java.lang.Thread.run:748
QUIT|11/28/2018 20:21:19.404|[SFTP:lookup:2222][8811356] Disconnected: xx.xx.xx.xx:21750


#6

Thanks - that bit of log was useful.

I can see that CrushFTP thinks it is removing a file not a directory. The backend was calling remove file not directory which works fine under unix based systems, but obviously not under windows based systems.

I’ve changed it to use remove directory instead which hopefully will fix it - can you give it a test please?

https://beta.rclone.org/branch/v1.45-009-g4b15c421-fix-sftp-rmdir-beta/ (uploaded in 15-30 mins)


#7

rmdir and --delete-empty-src-dirs work correctly with CrushFTP now. On the vendors sftp server (still do not know which sftp server software they are using) those options will delete the directories now but it will also allow directories which still have files in them to be deleted. It seems rmdir on whatever sftp server software they are using does not require the directory to be empty.


#8

Great!

I’ve merged that into the latest beta now.

Is that causing a problem?

The RFC is silent on whether that is allowed or not: https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-8.4

I can get rclone to check the directory is empty but that potentially slows down all ssh servers. However deleting the users files when you only did rmdir is bad! What do you think?


#9

I would think the potential slow down to check if the directory is empty before it is deleted is worth it to protect against potential data loss. Could this option be a flag instead of basic functionality in rmdir and --delete-empty-src-dirs? Then the user has the option for the additional check knowing it would potentially slow down the process.


#10

Hmm, I don’t like potential data loss, so I’ve put the check in regardless.

Can you give it a go here

https://beta.rclone.org/branch/v1.45-010-gb58f6811-fix-sftp-rmdir-beta/ (uploaded in 15-30 mins)


#11

Looks good. Here is the output of 2 tests, one with rmdir of a non-empty directory and the other with a move command that I excluded a file and used --delete-empty-src-dirs. Both worked as expected.

[centos@util-01 ~]$ rclone rmdir vendorsftp:testuser/testrmdir/testdir1 --log-level DEBUG
2018/11/30 20:20:25 DEBUG : rclone: Version “v1.45-010-gb58f6811-fix-sftp-rmdir-beta” starting with parameters [“rclone” “rmdir” “vendorsftp:testuser/testrmdir/testdir1” “–log-level” “DEBUG”]
2018/11/30 20:20:25 DEBUG : Using config file from “/home/centos/.config/rclone/rclone.conf”
2018/11/30 20:20:25 DEBUG : sftp://testuser@vendorsftp.example.com:22/testuser/testrmdir/testdir1: Removing directory
2018/11/30 20:20:25 ERROR : Attempt 1/3 failed with 1 errors and: directory not empty
2018/11/30 20:20:25 DEBUG : sftp://testuser@vendorsftp.example.com:22/testuser/testrmdir/testdir1: Removing directory
2018/11/30 20:20:26 ERROR : Attempt 2/3 failed with 1 errors and: directory not empty
2018/11/30 20:20:26 DEBUG : sftp://testuser@vendorsftp.example.com:22/testuser/testrmdir/testdir1: Removing directory
2018/11/30 20:20:26 ERROR : Attempt 3/3 failed with 1 errors and: directory not empty
2018/11/30 20:20:26 Failed to rmdir: directory not empty

[centos@util-01 ~]$ rclone move vendorsftp:testuser/testrmdir testsftp:testdir1 --delete-empty-src-dirs --exclude testdir1/testkeep1 --progress --log-level DEBUG
2018/11/30 20:21:24 DEBUG : rclone: Version “v1.45-010-gb58f6811-fix-sftp-rmdir-beta” starting with parameters [“rclone” “move” “vendorsftp:testuser/testrmdir” “testsftp:testdir1” “–delete-empty-src-dirs” “–exclude” “testdir1/testkeep1” “–progress” “–log-level” “DEBUG”]
2018/11/30 20:21:24 DEBUG : Using config file from “/home/centos/.config/rclone/rclone.conf”
2018-11-30 20:21:26 INFO : testdir2/test123: Copied (new)
2018-11-30 20:21:26 INFO : testdir2/test123: Deleted
2018-11-30 20:21:26 DEBUG : testdir1/testkeep1: Excluded
2018-11-30 20:21:26 INFO : sftp://rclonetest@sftp.example.com:2222/testdir1: Waiting for checks to finish
2018-11-30 20:21:26 INFO : sftp://rclonetest@sftp.example.com:2222/testdir1: Waiting for transfers to finish
2018-11-30 20:21:26 INFO : testdir1/test: Copied (new)
2018-11-30 20:21:26 INFO : testdir1/test: Deleted
2018-11-30 20:21:26 DEBUG : testdir1: Making directory
2018-11-30 20:21:26 DEBUG : testdir2: Making directory
2018-11-30 20:21:26 DEBUG : sftp://rclonetest@sftp.example.com:2222/testdir1: copied 2 directories
2018-11-30 20:21:26 DEBUG : testdir2: Removing directory
2018-11-30 20:21:27 DEBUG : testdir1: Removing directory
2018-11-30 20:21:27 DEBUG : testdir1: Failed to Rmdir: directory not empty
2018-11-30 20:21:27 DEBUG : sftp://testuser@vendorsftp.example.com:22/testuser/testrmdir: failed to delete 1 directories
2018-11-30 20:21:27 DEBUG : sftp://testuser@vendorsftp.example.com:22/testuser/testrmdir: deleted 1 directories
Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA -
Errors: 0
Checks: 2 / 2, 100%
Transferred: 2 / 2, 100%
Elapsed time: 2.6s
2018/11/30 20:21:27 INFO :
Transferred: 0 / 0 Bytes, -, 0 Bytes/s, ETA -
Errors: 0
Checks: 2 / 2, 100%
Transferred: 2 / 2, 100%
Elapsed time: 2.6s

2018/11/30 20:21:27 DEBUG : 29 go routines active
2018/11/30 20:21:27 DEBUG : rclone: Version “v1.45-010-gb58f6811-fix-sftp-rmdir-beta” finishing with parameters [“rclone” “move” “vendorsftp:testuser/testrmdir” “testsftp:testdir1” “–delete-empty-src-dirs” “–exclude” “testdir1/testkeep1” “–progress” “–log-level” “DEBUG”]


#12

Thank you for testing

I’ll merge that to master now so it will be in the latest beta in 15-30 mins.