External storage SFTP on a specific port

Hello all,

I’m trying to use a SFTP server but the port is not 22.

Since you cannot set a specific port, I’m trying to figure out a workaround:

  • I’ve checked the nextcloud.oc_external_config to see if I could modify a “port” row but it’s not the case.
  • By checking the log, I’ve gathered the php file to modify was /apps/files_external/lib/Lib/Storage/SFTP.php and line 47 I’ve changed “private $port = 22;” to “private $port = 2222;”

No luck, I don’t even see a connection attempt in the log of the sftp server.

Anyone know how I could force all SFTP connections to port 2222 instead of 21 ?

Thank you!

The file to modify is /var/www/html/nextcloud/apps/files_external/lib/Lib/Storage/SFTP.php

I’ve modified this line

$this->client = new \phpseclib\Net\SFTP($this->host, $this->port);

And it worked. I know it’s dirty but anyone has a better suggestion…

1 Like