I have successfully connected SFTP in magento 2 by referring the below URL:

How to connect SFTP in magento 2

Now, I want to send a file to that server. In order to send a file, how can I proceed?

Could anyone please help me with this?

 $serverInfo = [
                'host' => "host",
                'username' => "username",
                'password' => "pwd",
// use construct injection sftp : \Magento\Framework\Filesystem\Io\Sftp
$this->sftp->open($serverInfo); //the serverinfo is server config
$this->sftp->cd($path);//the path is you will upload path
$this->sftp->write($filename, $source); // filename and string data or local file name
  • Thanks. What I have to put to $path. Also Could you please explain a little bit about this code because I'm new to this SFTP? – Mohammad Dec 19 '19 at 10:17
  • The path of the ftp machine you want to upload. – Tokey Tu Dec 19 '19 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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