Just redirect the
php output to a temporary file and upload the file.
php yourscript.php > /tmp/file.csv echo "put /tmp/file.csv" | sftp firstname.lastname@example.org
If you want to do it without the temporary file, you cannot do with just the (OpenSSH)
sftp as it cannot read contents to upload from the stdin. Neither the (OpenSSH)
You can of course produce the file from PHP code itself, if that suits your task better.
Just use the
The suggestion by @MarcB should work, if the remote server is *nix (understands the
cat) and allows a shell access.
php yourscript.php | ssh email@example.com 'cat > file.csv'
Though obviously that's not "SFTP upload" anymore.
When producing a file, do not use the the
header(). Headers make sense in webserver environment only, not when you use the PHP as a scripting language in a shell.