0

I'm unable to move the generated csv file from my var/report folder to another sftp server.

Please help me.

2 Answers 2

0

If you want to Access the CSV file from the var/report directory then move to pub/ .

Now, you should be able to access the CSV file from anywhere within your server using the path http://your_domain/pub/file.csv or http://your_ip_address/pub/file.csv, depending on your server configuration.

0

Here are the steps, you can follow to move the var/report/filename to another server:

Step1: Create below constructor to the particular class.

public function __construct(
  \Magento\Framework\Filesystem\Io\Ftp $ftpConnection
){
    $this->ftpConnection = $ftpConnection;
}

Step2: Create a function & add below code:

$open = $this->ftpConnection->open(
    array(
        'host' => 'hostname',
        'user' => 'username',
        'password' => 'password',
        'ssl' => true,
        'passive' => true
    )
);

if ($open) {
    $fileName = 'report-filename'; // fetch the file name that you want to move
    $content = file_get_contents(DirectoryList::VAR_DIR . '/report' . $fileName);
    $this->ftpConnection->cd("--another server directory path--");
    $this->ftpConnection->write(self::FILE_NAME_ON_FTP, $content);
    $this->ftpConnection->close();
}

This will help you to move files from current server to another server.

Note: You can implement the above code to the CRON/controller/event/plugin or existing function to trigger it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.