0

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

Please help me.

Deepak MageDivine
4931 gold badge5 silver badges23 bronze badges
asked Jan 13, 2024 at 6:20

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.

answered Jan 13, 2024 at 11:13
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.

answered Jan 19, 2024 at 11:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.