Creating a filter to copy all PHP files but exclude one directory

What is the problem you are having with rclone?

I want to sync just the PHP files from my local filesystem to a remote FTP server, but excluding one directory (XYZ). I have created a filter file which I think should:

  • Include *.php files
  • Exclude directory XYZ which exists on the remote but not on local
  • Exclude anything else (effectively what --include would add automatically, but I'm using a filter because the documentation says not to mix --include and --exclude)

However, when I run rclone sync --dry-run it outputs deletion of the XYZ directory from the remote. I do not want to touch the XYZ directory at all - it needs to be completely omitted from consideration. I still need to do a sync rather than a copy because there will be PHP files that have been added, removed or changed.

I'm not sure exactly how to achieve what I want using filters, or even if it is possible. I've based my filter on one of the examples on the filtering documentation which seems to match what I want.

Run the command 'rclone version' and share the full output of the command.

rclone v1.65.0
- os/version: ubuntu 22.04 (64 bit)
- os/kernel: 5.15.0-91-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.21.4
- go/linking: static
- go/tags: none

Installed by downloading the .deb file from GitHub releases.

Which cloud storage system are you using? (eg Google Drive)

FTP (with explicit TLS)

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone sync --dry-run \
    ~/public_html/ staging-ftp:/public_html/ \
    --filter-from rclone-filters.txt

rclone-filters.txt contains:

+ *.php
- XYZ/**
- *

There is a blank line at the end of the file.

I have also tried:

+ *.php
- /XYZ/**
- *

i.e. adding an initial slash before XYZ.

Please run 'rclone config redacted' and share the full output. If you get command not found, please make sure to update rclone.

type = ftp
host = XXX
user = XXX
pass = XXX
explicit_tls = true
no_check_certificate = true

This is a shared hosting provider where the certificate doesn't match the host, hence not checking it.

A log from the command that you were trying to run with the -vv flag

I've had to just show some of the files here, as -vv doesn't redact hostnames, IP addresses etc. and these are confidential. However, I can confirm that rclone has no problems connecting to the server or copying files.

2023/12/21 14:21:03 NOTICE: vendor/tecnickcom/tcpdf/fonts/kozgopromedium.php: Skipped copy as --dry-run is set (size 3.493Ki)
2023/12/21 14:21:03 NOTICE: vendor/tecnickcom/tcpdf/fonts/kozminproregular.php: Skipped copy as --dry-run is set (size 3.373Ki)
2023/12/21 14:21:03 NOTICE: vendor/tecnickcom/tcpdf/fonts/msungstdlight.php: Skipped copy as --dry-run is set (size 1.514Ki)
2023/12/21 14:21:03 NOTICE: vendor/tecnickcom/tcpdf/fonts/pdfacourier.php: Skipped copy as --dry-run is set (size 2.560Ki)
2023/12/21 14:21:03 NOTICE: vendor/tecnickcom/tcpdf/fonts/pdfacourierb.php: Skipped copy as --dry-run is set (size 2.570Ki)
2023/12/21 14:21:08 NOTICE: XYZ/library/functions/phMagickExtended.class.php: Skipped delete as --dry-run is set (size 1.867Ki)
2023/12/21 14:21:08 NOTICE: XYZ/library/tcpdf/examples/example_034.php: Skipped delete as --dry-run is set (size 2.816Ki)
2023/12/21 14:21:08 NOTICE: XYZ/library/tcpdf/fonts/freemono.php: Skipped delete as --dry-run is set (size 26.562Ki)
2023/12/21 14:21:08 NOTICE: XYZ/library/display/old271009_page.class.php: Skipped delete as --dry-run is set (size 3.596Ki)

The first 5 files are scheduled for copying as I expect. The last 4 files I don't want synced (deleted in this case) as they are in the XYZ directory.

Filters go top down so you matched it with the first.

You generally want specific excludes first, the includes and then the drop all at the end.

- XYZ/**
+ *.php
- *

You can test with just rclone ls on the remote.

1 Like

Thanks, that seems to have done the trick (the example in the documentation lists includes first which is why I did them that way round).

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.