Uploading media files to a different FTP on upload complete

I am trying to use a filter to upload a file to a different ftp, before I save it , what am I doing wrong.

add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){

 $ftp_server = "*.*.*.*";
$ftp_user_name = "*******";
$ftp_user_pass = "*******";

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

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, 'public_html/wp-content/uploads/'.$file['name'], $file, FTP_ASCII)) {
    //delete local file
}

// close the connection
ftp_close($conn_id);

return $file;
}

Read more here: Uploading media files to a different FTP on upload complete

Leave a Reply

Your email address will not be published. Required fields are marked *