• Resolved udigital

    (@udigital)


    Hi There,
    I have tried several methods of being update products via a file on an external FTP server requiring a username and password. (https://ww.wp.xz.cn/support/topic/importing-from-ftp/)
    [custom_file_download("ftp://username:[email protected]/full/path/to/file.csv", "csv")]

    I have also tried the function code work around – both options give me a “There has been a critical error on your website.” error, which is displayed in the debug log as:

    PHP Fatal error:  Uncaught XmlImportException: Unexpected symbol '%' in /home/uniqxzhx/*******/wp-content/plugins/wp-all-import-pro/libraries/XmlImportTemplateScanner.php:180
    Stack trace:
    #0 /home/uniqxzhx/*******/wp-content/plugins/wp-all-import-pro/libraries/XmlImportParser.php(107): XmlImportTemplateScanner->scan(Object(XmlImportStringReader))
    #1 /home/uniqxzhx/*******/wp-content/plugins/wp-all-import-pro/actions/wp_ajax_upload_resource.php(35): XmlImportParser::factory('<?xml version="...', '/data/node', '[custom_file_do...', NULL)
    #2 /home/uniqxzhx/*******/wp-includes/class-wp-hook.php(288): pmxi_wp_ajax_upload_resource('')
    #3 /home/uniqxzhx/*******/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters('', Array)
    #4 /home/uniqxzhx/*******/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #5 /home/uniqxzhx/*******/wp-admin/admin-ajax.php(175): do_action('wp_ajax_upload_...')
    #6 {main}
      thrown in /home/uniqxzhx/*******/wp-content/plugins/wp-all-import-pro/libraries/XmlImportTemplateScanner.php on line 180

    The data-file is around 5MB in size

    Any assistance would be greatly appreciated.

    Thanks,
    Ricky

    • This topic was modified 6 years, 4 months ago by udigital.
    • This topic was modified 6 years, 4 months ago by udigital.
    • This topic was modified 6 years, 4 months ago by udigital.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @udigital

    Please try removing the space after the comma in the function call:

    [custom_file_download("ftp://username:[email protected]/full/path/to/file.csv","csv")]

    That should fix the error.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @udigital

    I am going to mark this as resolved since we haven’t heard back. Let us know if you still have questions regarding this. Anyone else, please open a new thread.

    danimaltheanimal

    (@danimaltheanimal)

    I have a password with a hash in it, so I used the following function instead for proper encoding, as it was throwing errors before.

    function custom_file_download($url, $type = 'xml', $user, $pass) {
    
        $ch = curl_init();
        curl_setopt_array(
            $ch,
            [
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_CUSTOMREQUEST => "GET",
                CURLOPT_USERNAME => $user,
                CURLOPT_PASSWORD => $pass
            ]
        );
    
    	// Retrieve file from $url.
    	$result = curl_exec( $ch );
    	echo $result .  PHP_EOL;
    	// Return error if cURL fails.
    	if ( curl_errno( $ch ) ) {
    		exit( 'Error:' . curl_errno( $ch ) .  PHP_EOL );
    	}
    	curl_close( $ch );
     
     
    	$uploads  = wp_upload_dir();
    	// Generate full file path and set extension to $type.
    	$filename = $uploads['basedir'] . '/' . strtok( basename( $url ), "?" ) . '.' . $type;
    		
    	 // If the file exists locally, mark it for deletion.
    	 if ( file_exists( $filename ) ) {
    		 @unlink( $filename );
    	 }
     
    	 // Save the new file retrieved from FTP.
    	 file_put_contents( $filename, $result );
    
    	 // Return the URL to the newly created file.
    	 return str_replace( $uploads['basedir'], $uploads['baseurl'], $filename );
    
    }

    however i’m getting the error:
    “The URL to your file is not valid.

    Please make sure the URL starts with http:// or https://. To import from https://, your server must have OpenSSL installed.

    Please help!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘FTP External File Import’ is closed to new replies.