Occ files:scan error for SFTP external storage ("Can't get app storage, app files_external, user not logged in)

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:


Or for longer, use three backticks above and below the code snippet:


Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 20.0.10
Operating system and version (eg, Ubuntu 20.04): Ubuntu 18.04
Apache or nginx version (eg, Apache 2.4.25): nginx 1.17.5
PHP version (eg, 7.4): 7.3.27-9

The issue you are facing:
Logged error message when executing file scan on SFTP external storage

Expected behavior: Update Nextcloud with the contents of external storage location

Actual behavior: Logged error message: “App:core, Message:Can’t get app storage, app files_external, user not logged in”

Is this the first time you’ve seen this error? (Y/N): I don’t recall this error being logged before upgrading to Nextcloud 20

Steps to replicate it:

  1. Create External Storage connection, using SFTP
  2. Execute ‘sudo -u www-data php occ files:scan --all’ or ‘sudo -u www-data php occ files:scan --path="[user]/files/[external_storage_mountpoint]"’

The output of your Nextcloud log in Admin > Logging:

{"reqId":"UhC3GUBUGaRXmGzP9jMu","level":3,"time":"2021-06-12T12:28:29-04:00","remoteAddr":"","user":"--","app":"core","method":"","url":"--","message":"Can't get app storage, app files_external, user not logged in","userAgent":"--","version":""}
{"reqId":"UhC3GUBUGaRXmGzP9jMu","level":3,"time":"2021-06-12T12:28:29-04:00","remoteAddr":"","user":"--","app":"core","method":"","url":"--","message":"Can't get app storage, app files_external, user not logged in","userAgent":"--","version":""}

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

    "system": {
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "",
        "overwrite.cli.url": "https:\/\/starkhome.org",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "activity_expire_days": 14,
        "auth.bruteforce.protection.enabled": true,
        "blacklisted_files": [
        "cron_log": true,
        "enable_previews": true,
        "enabledPreviewProviders": [
        "filesystem_check_changes": 0,
        "filelocking.enabled": "true",
        "htaccess.RewriteBase": "\/",
        "integrity.check.disabled": false,
        "knowledgebaseenabled": false,
        "logfile": "\/var\/nc_data\/nextcloud.log",
        "loglevel": 2,
        "logtimezone": "America\/New_York",
        "log_rotate_size": 104857600,
        "maintenance": false,
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "overwriteprotocol": "https",
        "preview_max_x": 1024,
        "preview_max_y": 768,
        "preview_max_scale_factor": 1,
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "timeout": 0
        "quota_include_external_storage": false,
        "share_folder": "\/",
        "skeletondirectory": "",
        "theme": "",
        "trashbin_retention_obligation": "auto, 7",
        "updater.release.channel": "stable",
        "mail_smtpmode": "smtp",
        "mail_smtpsecure": "ssl",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpauthtype": "LOGIN",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [
        "mail_smtpport": "465",
        "mail_smtpauth": 1,
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***"

The output of your Apache/nginx/system log in /var/log/____:

2021/06/12 12:27:56 [error] 8468#8468: r3.o.lencr.org could not be resolved (3: Host not found) while requesting certificate status, responder: r3.o.lencr.org, certificate: "/etc/letsencrypt/live/***REMOVED SENSITIVE VALUE***/fullchain.pem"

Did you ever resolve the issue or found a good way to debug ? I have the same issue - right now I have loglevel set at 2 and will try 0, but with a large amount of users the logs fill up fast.

I wish the error message included more details, it would make it for much easier debugging. Because a lot of the error messages seem to be generic googling them often does not result in finding good results. In the case of this issue I seem to get them when cron.php is run, at other times random, and I did get it when I run occ files:scan --all

With this error the message is: Can’t get app storage, app files_external, user not logged in - I would assume the system knows which user is creating the problem - why not say user XXXX not logged in ? I tried command occ files_external:list – for a user that I think may have the issue but don’t see anything obvious - their options are: enable_sharing: true, encoding_compatibility: true, previews: false - this is for a SFTP share.

I found the file where the error message is generated - around line 1098 in /var/www/nextcloud/lib/private/legacy/OC_App.php - not sure if the value of OC_User::getUser() is known when the test
if (\OC::$server->getUserSession()->isLoggedIn()) {
fails - if yes the error message should include the user name. I guess I will have to try to know for sure :grinning:

I recently upgraded to 21.0.3 and want to clean up all the errors in the log file, especially at the Error level and part of the Core. If people have good tricks to debugging those type of errors I would love to hear about them - thanks.

P.S. Sorry if this gets posted twice - got error 500 after pressing the Reply button

Ok - I tried the following but can’t trigger the error anymore - I restarted the Apache server ( which should not be needed when php files are changed ) and then run occ files:scan but it is not triggering the error message, as it was before - could restarting Apache fix this ?

added line 1099 in /var/www/nextcloud/lib/private/legacy/OC_App.php:
\OCP\Util::writeLog(‘core’, 'Can’t get app storage, app2 ’ . $appId . ‘, user ’ . OC_User::getUser() . ’ not logged in’, ILogger::ERROR);

I left the original error message, and added the above as a second line - in any case I have to remember to revert the change before doing any updates.

Looks like I had to refresh the logs to get the error - looks like OC_User::getUser() does not container the user - if there is another way to get the user name please let me know - thanks.