I ran into the bug seen here: https://github.com/magento/magento2/issues/9016. Basically, the library was updated but the Sftp.php file was not. I don't think I'm in a position or ready to run a major update at the moment so I need to patch this file or override it. I didn't see anything in the documentation as to what the preferred method is.
Can I simply copy the vendor/magento/framework/Filesystem/Io/Sftp.php file to app/code/magento/framework/Filesystem/Io/Sftp.php and make the change there as I would have in Magento 1 to override the file? What is considered best practice?
Edit- per Asrar's answer I've added:
Vendor/Namespace/etc/di.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\Filesystem\Io\Sftp" type="Vendor\Namespace\Model\Filesystem\Io\Sftp" />
</config>
Vendor/Namespace/Model/Filesystem/Io/Sftp.php:
...
/**
* @var \phpseclib\Net\SFTP $_connection
*/
protected $_connection = null;
...
...
/**
* Write a file
*
* @param string $filename
* @param string $source string data or local file name
* @param int $mode ignored parameter
* @return bool
*/
public function write($filename, $source, $mode = null)
{
$mode = is_readable($source) ? \phpseclib\Net\SFTP::SOURCE_LOCAL_FILE : \phpseclib\Net\SFTP::SOURCE_STRING;
return $this->_connection->put($filename, $source, $mode);
}
...
But I'm still throwing the same error.
Notice: Use of undefined constant NET_SFTP_LOCAL_FILE - assumed 'NET_SFTP_LOCAL_FILE' in .../magento/vendor/magento/framework/Filesystem/Io/Sftp.php on line 187
This must mean it's not reading my overrides. Can you see what I'm doing wrong?