Setting custom port from GUI broken for FTP and SFTP #32773
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
Bug description
Attempting to use an external FTP storage with a non-standard port fails. This is due to FtpConnection:__construct() getting the port to use from the GUI as part of the hostname argument and using the raw value as is. While PHP's ftp connect functions expect the hostname and port to be separate arguments.
This can also be seen in the cli:
$sudo php ./occ files_external:config mount id hostname
example.com:1234
$sudo php ./occ files_external:config mount id port
null
$
This will cause the debug log to get a PHP error from either ftp_ssl_connect() or ftp_connect(): getaddrinfo failed: Name or service not known
Steps to reproduce
- Enable external storage support.
- Add a new FTP or FTPS external storage configuration.
- Specify the non-standard port in the host box as per the instructions in the admin manual.
- Attempt to test the connection.
Expected behavior
FTP connection test to succeed and the external storage to be usable.
Installation method
Manual installation
Operating system
Debian/Ubuntu
PHP engine version
PHP 7.4
Web server
Apache (supported)
Database engine version
MariaDB
Is this bug present after an update or on a fresh install?
Updated from a minor version (ex. 22.2.3 to 22.2.4)
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
No response
List of activated Apps
Enabled:
- accessibility: 1.9.0
- activity: 2.15.0
- bruteforcesettings: 2.4.0
- calendar: 3.3.1
- circles: 23.1.1
- cloud_federation_api: 1.6.0
- comments: 1.13.0
- contacts: 4.1.1
- contactsinteraction: 1.4.0
- dashboard: 7.3.0
- dav: 1.21.0
- deck: 1.6.1
- federatedfilesharing: 1.13.0
- federation: 1.13.0
- files: 1.18.0
- files_accesscontrol: 1.13.0
- files_automatedtagging: 1.13.0
- files_external: 1.15.0
- files_pdfviewer: 2.4.0
- files_rightclick: 1.2.0
- files_sharing: 1.15.0
- files_trashbin: 1.13.0
- files_versions: 1.16.0
- files_videoplayer: 1.12.0
- firstrunwizard: 2.12.0
- groupfolders: 11.1.4
- impersonate: 1.10.0
- logreader: 2.8.0
- lookup_server_connector: 1.11.0
- mail: 1.13.1
- nextcloud_announcements: 1.12.0
- notifications: 2.11.1
- oauth2: 1.11.0
- password_policy: 1.13.0
- photos: 1.5.0
- privacy: 1.7.0
- provisioning_api: 1.13.0
- recommendations: 1.2.0
- richdocuments: 5.0.5
- richdocumentscode: 21.11.402
- serverinfo: 1.13.0
- settings: 1.5.0
- sharebymail: 1.13.0
- support: 1.6.0
- survey_client: 1.11.0
- systemtags: 1.13.0
- text: 3.4.1
- theming: 1.14.0
- twofactor_backupcodes: 1.12.0
- updatenotification: 1.13.0
- user_ldap: 1.13.1
- user_status: 1.3.1
- viewer: 1.7.0
- weather_status: 1.3.0
- workflowengine: 2.5.0
Disabled:
- admin_audit
- encryption
- spreed: 13.0.4
Nextcloud Signing status
No response
Nextcloud Logs
{"reqId":"NsjKBrLbJjZB15Pp3E28","level":3,"time":"2022-06-09T02:01:43+00:00","remoteAddr":"192.168.1.3","user":"27743958-36BD-4C10-9F27-FD772916DFCC","app":"PHP","method":"GET","url":"/index.php/apps/files_external/globalstorages/5?testOnly=true","message":"ftp_ssl_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known at /local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Lib/Storage/FtpConnection.php#35","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36","version":"23.0.5.1","exception":{"Exception":"Error","Message":"ftp_ssl_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known at /local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Lib/Storage/FtpConnection.php#35","Code":0,"Trace":[{"function":"onError","class":"OC\\Log\\ErrorHandler","type":"::"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Lib/Storage/FtpConnection.php","line":35,"function":"ftp_ssl_connect"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Lib/Storage/FTP.php","line":81,"function":"__construct","class":"OCA\\Files_External\\Lib\\Storage\\FtpConnection","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Lib/Storage/FTP.php","line":189,"function":"getConnection","class":"OCA\\Files_External\\Lib\\Storage\\FTP","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/MountConfig.php","line":130,"function":"test","class":"OCA\\Files_External\\Lib\\Storage\\FTP","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Controller/StoragesController.php","line":288,"function":"getBackendStatus","class":"OCA\\Files_External\\MountConfig","type":"::","args":["*** sensitive parameters replaced ***"]},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/apps/files_external/lib/Controller/StoragesController.php","line":363,"function":"updateStorageStatus","class":"OCA\\Files_External\\Controller\\StoragesController","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":217,"function":"show","class":"OCA\\Files_External\\Controller\\StoragesController","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/lib/private/AppFramework/Http/Dispatcher.php","line":126,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/lib/base.php","line":1008,"function":"match","class":"OC\\Route\\Router","type":"->"},{"file":"/local_data/Manually_Installed/Web_Applications/nextcloud/index.php","line":36,"function":"handleRequest","class":"OC","type":"::"}],"File":"/local_data/Manually_Installed/Web_Applications/nextcloud/lib/private/Log/ErrorHandler.php","Line":92,"CustomMessage":"--"},"id":"62a1548869b19"}
Additional info
As a workaround, manually setting the port for the external storage via the occ command on the CLI will allow the connection to work.
E.x.
$sudo php ./occ files_external:config mount_id host example.com
$sudo php ./occ files_external:config mount_id port 1234
Activity