For some FTP servers, it seems the sequence of passive and other commands matters more than for other FTP servers. Sorry, I don't know what vendor or version specifically.
<?php
ftp_pasv($handle, true);
echo "System type: ".ftp_systype($handle).PHP_EOL;
ftp_fput($handle, 'example.txt', $stream, FTP_BINARY);
?>
> PHP Warning: ftp_fput(): STOR out of sequence.
<?php
echo "System type: ".ftp_systype($handle).PHP_EOL;
ftp_pasv($handle, true);
ftp_fput($handle, 'example.txt', $stream, FTP_BINARY);
?>
> no issue