I have a sample CSV file and want to send it to another server using FTP. I have successfully connected FTP but couldn't able to send the file.
In the FTP where I want to send, there are 2 folders named Import and Export. I have checked those folders but I can't see the file which I sent. I didn't get any error as well. So, I'm not sure, where am I wrong.
In order to send the file using FTP, I have followed the below link:
Would anyone please help me to resolve this issue?
Code:
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$sftp = $objectManager->create('Magento\Framework\Filesystem\Io\Sftp');
$open = $sftp->open(
array(
'host' => 'hostname',
'username' => 'xyz',
'password' => 'pwd',
'port' =>22,
'passive' => true
)
);
if ($open) {
$fileName = ‘sample.csv’;
$content = file_get_contents(DirectoryList::VAR_DIR . '/' . $fileName);
$this->ftp->write(self::FILE_NAME_ON_FTP, $content);
$this->ftp->close();
}
if(is_null($connection)){
echo "true";
//Here is code ....
}else{
echo "false";
}
self::FILE_NAME_ON_FTP
?self::FILE_NAME_ON_FTP
. and check root folder of the server...Means before public_html