Skip to content

Instantly share code, notes, and snippets.

@Programmer095
Forked from trey8611/data_feed.php
Last active May 1, 2018 09:09
Show Gist options
  • Save Programmer095/2cdf89553f1eb286742387aa617520a0 to your computer and use it in GitHub Desktop.
Save Programmer095/2cdf89553f1eb286742387aa617520a0 to your computer and use it in GitHub Desktop.

Revisions

  1. Programmer095 revised this gist Dec 18, 2017. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions data_feed.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,11 @@
    <?php
    /*
    ################### READ ME #################################
    You must create a proxy file that retrieves your import file from FTP and then returns it.
    You will then call that file with the 'Download from URL' option in WP All Import.
    This is an example of such a proxy file. This is provided in the hopes it is useful, but without any support.
    ###############################################################
    */
    $ftp = array(
    'server' => 'ftp.example.com',
    'user' => 'yourusername',
  2. @trey8611 trey8611 created this gist Jun 10, 2016.
    64 changes: 64 additions & 0 deletions data_feed.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php
    $ftp = array(
    'server' => 'ftp.example.com',
    'user' => 'yourusername',
    'pass' => 'yourpassword'
    );

    // Connect
    $ftp_connection = ftp_connect( $ftp['server'] ) or die( 'Could not connect to $ftp[$server]' );

    // Set passive mode
    ftp_pasv( $ftp_connection, false );

    if ( $login = ftp_login( $ftp_connection, $ftp['user'], $ftp['pass'] ) ) {

    // Login passed

    // Download data to this file.
    $local_file = 'datafeed.csv.';

    // Path and filename to open and read from.
    $server_file = 'public_html/ftpfiles/data-example-2.csv';

    // Download File
    if ( $file = ftp_get( $ftp_connection, $local_file, $server_file, FTP_ASCII ) ) {

    $handle = fopen( $local_file, "r" ) or die( "Couldn't get handle" );

    if ( $handle ) {

    while ( !feof( $handle ) ) {

    // Output data.
    $buffer = fgets( $handle, 4096 );
    echo $buffer;

    }

    fclose( $handle );

    } else {

    // $handle failed
    echo "Failed to get handle.";

    }

    } else {

    // ftp_get failed
    echo "Failed to download file.";

    }

    } else {

    // Login failed
    echo "Failed to log in.";

    }

    // Disconnect
    ftp_close( $ftp_connection );
    ?>