Q:

PHP sending text files by ftp_fput results with blank files

I have a PHP script that:

Runs a query on a database
the returned data is written to text files
The text files are then sent via FTP to anothe server

Everything works fine and the text files are generated with data in them. 
When the files are sent thru FTP the files are created on the Receiving Server but are empty. 
This is the relevant code:
if ($result = mysqli_query($db,$qry)){

   echo "Found Records</br>";

   $fd1 = fopen($fpath.$filename1, "w+");
   $fd2 = fopen($fpath.$filename2, "w+");

   while ($row = $result->fetch_assoc()) {
        // Populate text files with data    
        ...
   }
}
mysqli_close($db);

//FTP text files to another server

$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

if (ftp_fput($ftp_conn, $filename1, $fd1, FTP_ASCII)) {
    echo "Successfully uploaded $filename1\n";
} else {
    echo "There was a problem while uploading $filename1\n";
}

if (ftp_fput($ftp_conn, $filename2, $fd2, FTP_ASCII)) {
   echo "Successfully uploaded $filename2\n";
} else {
   echo "There was a problem while uploading $filename2\n";
}

ftp_close($ftp_conn);
fclose($fd1);
fclose($fd2);

A:

I was able to make it work once I closed the filestreams 
and used ft_put() instead of ft_fput()

