I am trying to upload a custom exported CSV to another server FTP on particular location.
Step 1: Added FTP Class in constructor
protected $ftp;
public function __construct(
\Magento\Framework\Filesystem\Io\Ftp $ftp
){
$this->ftp = $ftp;
}
Step 2: Build the FTP Connect
$open = $this->ftp->open(
array(
'host' => 'myhostname',
'user' => 'username',
'password' => 'password',
'ssl' => true,
'passive' => true
)
);
Step 3: Use the written function to upload a file to the server
if ($open) {
$fileName = 'myfile.csv';
$content = file_get_contents(DirectoryList::VAR_DIR . '/pub/media/report' . $fileName);
$this->ftp->write(self::FILE_NAME_ON_FTP, $content);
$this->ftp->close();
}
The above code is working but I wanted to send file to particular location.
Issue: I want to send file from my server path pub/media/reports
to another server path var/www/html/myfoldername/pub/media/reports
Please help me!!