Uploading files with SFTP

With the method above (involving sftp) you can use stream_copy_to_stream:

$resFile = fopen("ssh2.sftp://{$resSFTP}/".$csv_filename, 'w');
$srcFile = fopen("/home/myusername/".$csv_filename, 'r');
$writtenBytes = stream_copy_to_stream($srcFile, $resFile);
fclose($resFile);
fclose($srcFile);

You can also try using ssh2_scp_send

Leave a Comment