You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
step6: add sftp config settings: user should be username, not 'user'
SFTP
Host
Port
Username
Password
You will be able to define file path during import/export process
this makes sftp available and product import works with sftp.
FIREBEAR:No one using ftp now days and not secure. Please start adding some secure points to module if you build and sell it. We bought it and finally added our own code to work.
step1 : add new file to following location: Firebear\ImportExport\Model\Filesystem\Io => Sftp.php
_conn, $filename); } } **step2 :** add test case to Firebear\ImportExport\Test\Unit\Model\Source\Type => SftpTest.php objectManagerHelper = new ObjectManagerHelper($this); $this->_sftpClient = $this->getMockBuilder('Firebear\ImportExport\Model\Filesystem\Io\Sftp') ->setMethods( [ 'read' ] ) ->getMock(); $this->_sftpClient->expects($this->any()) ->method('read') ->willReturn(true); $this->varDirectory = $this->getMock( 'Magento\Framework\Filesystem\Directory\Write', ['getAbsolutePath'], [], '', false ); //$this->varDirectory->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(true)); $this->filesystem = $this->getMock( 'Magento\Framework\Filesystem', ['getDirectoryWrite'], [], '', false ); $this->filesystem->expects($this->any())->method('getDirectoryWrite')->willReturn($this->varDirectory); $this->factory = $this->getMock('Magento\Framework\Filesystem\File\ReadFactory', [], [], '', false); $this->scopeConfigInterface = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'); $this->_sftpMock = $this->objectManagerHelper->getObject( 'Firebear\ImportExport\Model\Source\Type\Sftp', [ 'scopeConfig' => $this->scopeConfigInterface, 'filesystem' => $this->filesystem, 'readFactory' => $this->factory ] ); $this->_sftpMock->setClient($this->_sftpClient); // $this->_ftpMock = $this->getMockBuilder('Firebear\ImportExport\Model\Source\Type\Ftp') // ->setConstructorArgs( // [ // $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface') // ->disableOriginalConstructor() // ->getMock(), // $this->getMockBuilder('Magento\Framework\Filesystem') // ->disableOriginalConstructor() // ->getMock(), // $this->getMockBuilder('Magento\Framework\Filesystem\File\ReadFactory') // ->disableOriginalConstructor() // ->getMock(), // ] // ) // ->setMethods( // [ // 'uploadSource', // '_getSourceClient', // ] // ) // ->getMock(); // // $this->_ftpMock->expects($this->any()) // ->method('_getSourceClient') // ->willReturn($this->_ftpClient); $this->_sftpMock->setData('import_source', 'sftp'); $this->_sftpMock->setData('sftp_file_path', '/public_html/import/products_2_replace.csv'); } public function testUploadSource() { try { $result = $this->_sftpMock->uploadSource(); } catch (\Exception $e) { $result = $e->getMessage(); } $this->assertEquals('/var/www/local-mage2dev.com/magento2/var/import/sftp/products_2_replace.csv', $result); } } **step3:** add sftp source to Firebear\ImportExport\Model\Source\Type => Sftp.php */ namespace Firebear\ImportExport\Model\Source\Type; class Sftp extends AbstractType { /** * @var string */ protected $_code = 'sftp'; /** * Download remote source file to temporary directory * * @return string * @throws \Magento\Framework\Exception\LocalizedException */ public function uploadSource() { if($client = $this->_getSourceClient()) { $sourceFilePath = $this->getData($this->_code . '_file_path'); $fileName = basename($sourceFilePath); //return get_class($this->_directory); $filePath = $this->_directory->getAbsolutePath($this->getImportPath() . '/' . $fileName); $filesystem = new \Magento\Framework\Filesystem\Io\File(); $filesystem->setAllowCreateFolders(true); $filesystem->checkAndCreateFolder($this->_directory->getAbsolutePath($this->getImportPath())); $result = $client->read($sourceFilePath, $filePath); if($result) { return $this->_directory->getAbsolutePath($this->getImportPath() . '/' . $fileName); } else { throw new \Magento\Framework\Exception\LocalizedException(__("File not found")); } } else { throw new \Magento\Framework\Exception\LocalizedException(__("Can't initialize %s client", $this->_code)); } } /** * Download remote images to temporary media directory * * @param $importImage * @param $imageSting * * @throws \Magento\Framework\Exception\LocalizedException */ public function importImage($importImage, $imageSting) { if($client = $this->_getSourceClient()) { $sourceFilePath = $this->getData($this->_code . '_file_path'); $sourceDirName = dirname($sourceFilePath); $filePath = $this->_directory->getAbsolutePath($this->getMediaImportPath() . $imageSting); $dirname = dirname($filePath); if (!is_dir($dirname)) { mkdir($dirname, 0775, true); } if($filePath) { $result = $client->read($sourceDirName . '/' . $importImage, $filePath); } } } /** * Check if remote file was modified since the last import * * @param int $timestamp * @return bool|int */ public function checkModified($timestamp) { if($client = $this->_getSourceClient()) { $sourceFilePath = $this->getData($this->_code . '_file_path'); if(!$this->_metadata) { $this->_metadata['modified'] = $client->mdtm($sourceFilePath); } $modified = $this->_metadata['modified']; return ($timestamp != $this->_metadata['modified']) ? $modified : false; } return false; } /** * Prepare and return SFTP client * * @return \Firebear\ImportExport\Model\Filesystem\Io\Sftp * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getSourceClient() { if(!$this->getClient()) { if($this->getData('host') && $this->getData('port') && $this->getData('user') && $this->getData('password')) { $settings = $this->getData(); } else { $settings = $this->_scopeConfig->getValue( 'firebear_importexport/sftp', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } $settings['passive'] = true; try { $connection = new \Firebear\ImportExport\Model\Filesystem\Io\Sftp(); $connection->open( $settings ); $this->_client = $connection; } catch(\Exception $e){ throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage())); } } return $this->getClient(); } } **step 4:** add source types to /Firebear/ImportExport/etc/ => source_types.xmlstep5 : change config.xml :
22
step6: add sftp config settings: user should be username, not 'user'
SFTP
Host
Port
Username
Password
You will be able to define file path during import/export process
this makes sftp available and product import works with sftp.
FIREBEAR:No one using ftp now days and not secure. Please start adding some secure points to module if you build and sell it. We bought it and finally added our own code to work.
Uploading sftp.zip…
The text was updated successfully, but these errors were encountered: