ftp_put transfers file but file is empty?

Viewed 30

I wrote a function to generate a CSV file via PHP and store it on my FTP. It works fine and generates the file correctly. But after that I want to transfer it to another FTP server. But after the transfer the file is there but the file is empty while it is not on my FTP where it is generated.

//Headers info
$headers = array('Firstname', 'Lastname');
//Build form data
    
$data = array(
    'firstname' => 'My first name',
    'lastname' => 'My last name',
);
    
$filename = 'csv_'.$data['firstname'].'_'.$data['lastname'].'_file.csv';

//Open or Create CSV File
$fh = fopen($filename, 'a');
fputcsv($fh, $headers); 
fputcsv($fh,$data);
        
//Close the file
fclose($fh);
        
    
//Upload to external FTP    
$file = $filename;
$remote_file = '/' . $filename;
$ftp_server = 'host';
$ftp_user_name = 'username';
$ftp_user_pass = 'password';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);    
    
// upload a file
ftp_put($conn_id, $remote_file, $file, FTP_ASCII);

// close the connection
ftp_close($conn_id);
    
0 Answers
Related