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 …
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
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.
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?
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.
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?
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.
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”]