Improve default Magento 2 Import / Export features - cron jobs, CSV , XML , JSON , Excel , mapping of any format, Google Sheet, data and price modification, improved speed and a lot more!
@return int
*/
public function mdtm($filename)
{
return @ftp_mdtm($this->_conn, $filename);
}
}
step2 :
add test case to Firebear\ImportExport\Test\Unit\Model\Source\Type => SftpTest.php
<?php
namespace Firebear\ImportExport\Test\Unit\Model\Source\Type;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
class SftpTest extends \PHPUnit_Framework_TestCase
{
/**
step6: add sftp config settings: user should be username, not 'user'
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 <?php /**
/**
step2 : add test case to Firebear\ImportExport\Test\Unit\Model\Source\Type => SftpTest.php <?php namespace Firebear\ImportExport\Test\Unit\Model\Source\Type;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface; use Magento\Framework\App\Filesystem\DirectoryList;
class SftpTest extends \PHPUnit_Framework_TestCase { /**
@var ObjectManagerHelper */ protected $objectManagerHelper;
protected $_sftpClient; protected $_sftpMock;
protected $varDirectory; protected $filesystem; protected $factory; protected $scopeConfigInterface;
protected function setUp() { parent::setUp();
// $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);
}
step3: add sftp source to Firebear\ImportExport\Model\Source\Type => Sftp.php <?php /**
namespace Firebear\ImportExport\Model\Source\Type;
class Sftp extends AbstractType { /**
@var string */ protected $_code = 'sftp';
/**
@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()));
}
/**
@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); } } }
/**
@return bool|int */ public function checkModified($timestamp) { if($client = $this->_getSourceClient()) { $sourceFilePath = $this->getData($this->_code . '_file_path');
}
/**
@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 ); }
} }
step 4: add source types to /Firebear/ImportExport/etc/ => source_types.xml <?xml version="1.0"?>
step5 : change config.xml :
step6: add sftp config settings: user should be username, not 'user'
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…]()