Some files could not be synced: .htaccess

Hi

i have just installed NextCloud, and was quite happy, but…
i took all the files that I have in my ICloud synced folder and added them to my NextCloud folder and some files cannot be synced like a .htaccess file - sure I know what type of file this is, but what does that have to do with a synced folder ?

And how do I fix that ?

Thanks

Kind regards
Steen

The .htaccess file is hidden on Linux web servers and should not be touched, because it is needed for security of the Nextcloud server f.ex. to grant access to authorized users only). It should be excluded from any synchronisation.

The folder is not a web server folder, it’s a normal folder that happens to be copy of a website, but not a real website.

On a Mac
Let’s say i have this:

/Users/my_user/NextCloud/somefolder/index.hml
/Users/my_user/NextCloud/somefolder/.htaccess

The index.html is synced, but the .htaccess is not.

Then the folder ā€œsomefolderā€ was copied from a website or from the Nextcloud user folder. Because it will not be displayed in Nextcloud, you will find it on the nextcloud server in the Nextcloud data folder or/and its subfolders.

btw.: Please look at the Nextcloud desktop client. In the settings you will find a list of files to be ignored, .htaccess is one of them.

P.S.: Syncing ONE folder to TWO cloud softwares will lead you into trouble beacause of unexpected events, in many cases with data-loss.

The problem is, if you upload to Nextcloud, Nextcloud runs on a webserver that might interprete this .htaccess which is potentially a problem, e.g. this is the webdav path for this file:

https://nc.example.com/remote.php/dav/files/my_user/NextCloud/somefolder/.htaccess

I’m not trying to sync the same folder to two different services.

I installed the NextCould desktop client, I then went to my ICloud folder, selected all, copy and then paste into my NextCloud folder, and then - after some time - I saw the error

the .htaccess is not on the ā€˜Ignored lsit’ in the settings of my desktop client

I understand what a .htaccess file is, that is not the issue.

For me, my NextCloud is a place to store files, any file I choose just as I can on Google Drive, ICloud, DropBox or OneDrive - In fact I’m trying to get out of Google Drive, ICloud and OneDrive.

if there is files I choose to add to the Ignore list then its fine that it get’s ignored and most of the files that is on the Ignored list make sense.
If a file is not on the ignored list I should be able to save it - IHMO.

I do also understand that NextClould uses Apache in the AIO default installation so I absolutely understand that a .htaccess file in the wrong place could make a mess, but… I’m just uploading files to a folder that is managed by NextCloud so that should not be a problem - IMO

What’s next, can I not store .sh, .bat .cgi .php files ?

Yes, you can.

Did you check on the server, whether a .htaccess files exists in the target folder of the Nextcloud server? - Maybe the desktop client gives an error, because it can not be overwritten (as designed).

I recommend to add .htaccess to ignored files list

If you don’t use apache and/or the data folder is outside the webserver folder (so you can only access via php), you can modify the code and disable this check. I don’t know if there are other implications.

If that works, and you don’t want to modify it on your own, you can ask to change this and propose a pull request. And to break nothing with old/existing setups, keep the current behavior default, and put enough warnings that nobody does not turn this feature on by accident.

1 Like

No, do not modify code! No code modifiction or even disabling of checks necessary!

and no pull request necessary eather!

This line of code in FilenameValidator::getForbiddenFilenames() is really not that hard to understand:

$forbiddenNames = $this->getConfigValue('forbidden_filenames', ['.htaccess']);

here the value for 'forbidden_filenames' is only pre-set/pre-filled with '.htaccess'. That default can be overridden by setting an empty array:

  'forbidden_filenames' => array (),

BUT — (don’t stop reading here)

.. because the legacy key 'blacklisted_files' is still read (until Nextcloud 34) and the two lists are merged (into each other), you must also clear the legacy key. Therefore add both entries to config/config.php (tested solution):

  'blacklisted_files' => array (),
  'forbidden_filenames' => array (),

Once both keys are empty, syncing '.htaccess' files should work.

If it doesn’t work immediately, it’s because the 'opcache.revalidate_freq' value in php.ini is too high. Then just wait a moment and try again.

h.t.h.

Much and good luck,


ernolf

ah ok, I thought it was always added to the list.