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

return $file;

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


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: