• Resolved ammaribrahim

    (@ammaribrahim)


    hi
    I have question with this code

    
    
    function wpae_after_export( $export_id ) {
    
        // Retrieve export object.
        $export = new PMXE_Export_Record();
        $export->getById($export_id);
        
        // Check if "Secure Mode" is enabled in All Export > Settings.
        $is_secure_export = PMXE_Plugin::getInstance()->getOption('secure');
    
        // Retrieve file path when not using secure mode.
        if ( !$is_secure_export) {
            $filepath = get_attached_file($export->attch_id);
    
        // Retrieve file path when using secure mode.                    
        } else {
            $filepath = wp_all_export_get_absolute_path($export->options['filepath']);
        }
    
        // Path to the export file.
        $localfile = $filepath;
    
        // File name of remote file (destination file name).
        $remotefile = basename($filepath);
        
        // Remote FTP server details.
        // The 'path' is relative to the FTP user's login directory.
        $ftp = array(
            'server' => 'enter-hostname-here',
            'user' => 'enter-user-here',
            'pass' => 'enter-password-here',
            'path' => '/enter/path/to/folder/here'
        );
    
        // Ensure username is formatted properly
        $ftp['user'] = str_replace('@', '%40', $ftp['user']);
        
        // Ensure password is formatted properly
        $ftp['pass'] = str_replace(array('#','?','/','\\'), array('%23','%3F','%2F','%5C'), $ftp['pass']);
        
        // Remote FTP URL.
        $remoteurl = "ftp://{$ftp['user']}:{$ftp['pass']}@{$ftp['server']}{$ftp['path']}/{$remotefile}";
    
        // Retrieve cURL object.
        $ch = curl_init();
    
        // Open export file.
        $fp = fopen($localfile, "rb");
        
        // Proceed if the local file was opened.
        if ($fp) {
            
            // Provide cURL the FTP URL.
            curl_setopt($ch, CURLOPT_URL, $remoteurl);
    
            // Prepare cURL for uploading files.
            curl_setopt($ch, CURLOPT_UPLOAD, 1);
    
            // Provide the export file to cURL.
            curl_setopt($ch, CURLOPT_INFILE, $fp);
    
            // Provide the file size to cURL.
            curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
            
            // Start the file upload.
            curl_exec($ch);
    
            // If there is an error, write error number & message to PHP's error log.
            if($errno = curl_errno($ch)) {
                if (version_compare(phpversion(), '5.5.0', '>=')) {
                    
                    // If PHP 5.5.0 or greater is used, use newer function for cURL error message.
                    $error_message = curl_strerror($errno);
    
                } else {
    
                    // Otherwise, use legacy cURL error message function.
                    $error_message = curl_error($ch);
                }
    
                // Write error to PHP log.
                error_log("cURL error ({$errno}): {$error_message}");
    
            }
            
            // Close the connection to remote server.
            curl_close($ch);
            
        } else {
    
            // If export file could not be found, write to error log.
            error_log("Could not find export file");
    
        }
    }
    
    add_action('pmxe_after_export', 'wpae_after_export', 10, 1);
    
    

    Frind After I updated the server info , where I can I put this code in function section for wp all export is that right ?? I made that but the code not working
    or any steps should I do
    my id for export is 8

    any small information about the corect steps I will appreciate that
    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter ammaribrahim

    (@ammaribrahim)

    any help ?

    Plugin Author WP All Import

    (@wpallimport)

    Hi @ammaribrahim,

    Frind After I updated the server info , where I can I put this code in function section for wp all export is that right ??

    Yes, that would work.

    I made that but the code not working or any steps should I do

    I would suggest checking the PHP error log to see if the code logged anything there, and also using the options API to set debug points to see where the code is failing: https://codex.www.ads-software.com/Options_API.

    Thread Starter ammaribrahim

    (@ammaribrahim)

    thanks for reply

    I see this code for FTP server , can I use SFTP server information ?
    thanks

    Thread Starter ammaribrahim

    (@ammaribrahim)

    I checked
    log php error I see this

    [15-Sep-2021 04:17:51 UTC] cURL error (3): URL using bad/illegal format or missing URL

    Plugin Author WP All Import

    (@wpallimport)

    Hi @ammaribrahim,

    I see this code for FTP server , can I use SFTP server information ?

    SFTP should work as well.

    [15-Sep-2021 04:17:51 UTC] cURL error (3): URL using bad/illegal format or missing URL

    This means you need to double check the URL you’re using and make sure it’s in the correct format and doesn’t contain any illegal characters.

    If you need further help with your code, this is a good place to search/ask: https://stackoverflow.com/.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @ammaribrahim,

    I’m marking this as resolved since it’s been inactive for a while. Feel free to open a new topic if you still have questions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘sent export file to FTP in Other server’ is closed to new replies.