Skip to content

Instantly share code, notes, and snippets.

@trey8611
Forked from m-thomson/import-ftp-proxy.php
Last active February 18, 2022 16:56
Show Gist options
  • Select an option

  • Save trey8611/b7df39e7c5b09776c0ffc17dd4e2ead1 to your computer and use it in GitHub Desktop.

Select an option

Save trey8611/b7df39e7c5b09776c0ffc17dd4e2ead1 to your computer and use it in GitHub Desktop.

Revisions

  1. trey8611 revised this gist May 7, 2020. No changes.
  2. @m-thomson m-thomson revised this gist Sep 2, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions import-ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,7 @@
    // If you're experiencing problems you can uncomment the following line so errors will be sent to the file.
    // ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
    //
    // Enter the FTP (or HTTP) URL of your data file below. IMPORTANT: This must contain the FULL PATH of the
    // file. PHP seems to always start from the root folder rather than the default folder for the given user.
    // Enter the FTP (or HTTP) URL of your data file below.
    $url = "ftp://username:[email protected]/full/path/to/file.csv";

    // These headers aren't strictly needed but can be helpful
  3. Mark Thomson revised this gist Feb 1, 2017. No changes.
  4. Mark Thomson revised this gist Feb 1, 2017. No changes.
  5. Mark Thomson revised this gist Jan 22, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions import-ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    <?php
    // Note: Anyone could access your data if they guess this URL. You should remove this file from the server
    // after importing or name it to something "unguessable". For even better security use an .htaccess rule.

    //
    // If you're experiencing problems you can uncomment the following line so errors will be sent to the file.
    // ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

    // Enter the FTP (or HTTP) URL of your data file here. IMPORTANT: This must contain the FULL PATH of the
    //
    // Enter the FTP (or HTTP) URL of your data file below. IMPORTANT: This must contain the FULL PATH of the
    // file. PHP seems to always start from the root folder rather than the default folder for the given user.
    $url = "ftp://username:[email protected]/full/path/to/file.csv";

  6. Mark Thomson revised this gist Jan 22, 2017. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions import-ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,13 @@
    <?php
    /*
    * Note: Anyone could access your data if they guess this URL. You should remove
    * this file from the server after importing or rename it to something "unguessable"
    * like 'proxy-24dxfi3.php'. For even better security use an .htaccess rule.
    */
    // Note: Anyone could access your data if they guess this URL. You should remove this file from the server
    // after importing or name it to something "unguessable". For even better security use an .htaccess rule.

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";
    // If you're experiencing problems you can uncomment the following line so errors will be sent to the file.
    // ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

    // Enter the FTP (or HTTP) URL of your data file here. IMPORTANT: This must contain the FULL PATH of the
    // file. PHP seems to always start from the root folder rather than the default folder for the given user.
    $url = "ftp://username:[email protected]/full/path/to/file.csv";

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
  7. Mark Thomson revised this gist Dec 15, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion import-ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment');
    header('Content-Disposition: attachment; filename="ftp-proxy-data.txt"');
    header('Pragma: no-cache');

    // Fetch the file and echo it
  8. Mark Thomson renamed this gist Dec 15, 2016. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions ftp-proxy.php → import-ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,8 @@
    <?php
    /*
    * Security note: Anyone could access your data if they guess this URL.
    * You should remove this file from the server after importing or rename
    * to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') But understand,
    * that method is not perfectly secure. For best security use an .htaccess
    * rule allowing access only from localhost.
    * Note: Anyone could access your data if they guess this URL. You should remove
    * this file from the server after importing or rename it to something "unguessable"
    * like 'proxy-24dxfi3.php'. For even better security use an .htaccess rule.
    */

    // Enter the FTP (or HTTP) URL of your data file here.
  9. Mark Thomson revised this gist Dec 15, 2016. 3 changed files with 19 additions and 22 deletions.
    7 changes: 0 additions & 7 deletions !_import_ftp-proxy.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    Since WP All Import only supports fetching data files over HTTP or HTTPS, many users employ their own proxy script in PHP to act as an intermediary. This script would read the data file from the FTP server and output it over HTTP (for consumption by WP All Import).

    For example, you could have a PHP script on your server called `ftp-proxy.php` and then tell WP All Import to import from that URL:

    `http://example.com/ftp-proxy.php`

    *Security note: Anyone could access your data if they guess this URL.We recommend either removing this file from the server after you've run your import or renaming this file to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') but understand that method is not perfectly secure. For best security use an .htaccess rule allowing access only from localhost.*
    15 changes: 0 additions & 15 deletions ftp-proxy-simple.php
    Original file line number Diff line number Diff line change
    @@ -1,15 +0,0 @@
    <?php
    /*
    Security note: Anyone could access your data if they guess this URL.We recommend either removing this file from the server after you've run your import or renaming this file to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') but understand that method is not perfectly secure. For best security use an .htaccess rule allowing access only from localhost.
    */

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment');
    header('Pragma: no-cache');

    // Fetch the file and echo it
    readfile($url);
    19 changes: 19 additions & 0 deletions ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php
    /*
    * Security note: Anyone could access your data if they guess this URL.
    * You should remove this file from the server after importing or rename
    * to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') But understand,
    * that method is not perfectly secure. For best security use an .htaccess
    * rule allowing access only from localhost.
    */

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment');
    header('Pragma: no-cache');

    // Fetch the file and echo it
    readfile($url);
  10. Mark Thomson revised this gist Dec 15, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions ftp-proxy-simple.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    <?php
    /*
    Security note: Anyone could access your data if they guess this URL.We recommend either removing this file from the server after you've run your import or renaming this file to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') but understand that method is not perfectly secure. For best security use an .htaccess rule allowing access only from localhost.
    */

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";
  11. Mark Thomson revised this gist Dec 15, 2016. 2 changed files with 1 addition and 29 deletions.
    2 changes: 1 addition & 1 deletion !_import_ftp-proxy.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,4 @@ For example, you could have a PHP script on your server called `ftp-proxy.php` a

    `http://example.com/ftp-proxy.php`

    Security note: Anyone could access your data if they guess this URL.We recommend either removing this file from the server after you've run your import or renaming this file to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') but understand that method is not perfectly secure. For best security use an .htaccess rule allowing access only from localhost.
    *Security note: Anyone could access your data if they guess this URL.We recommend either removing this file from the server after you've run your import or renaming this file to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') but understand that method is not perfectly secure. For best security use an .htaccess rule allowing access only from localhost.*
    28 changes: 0 additions & 28 deletions ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -1,28 +0,0 @@
    <?php

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment');
    header('Pragma: no-cache');

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";

    // Open remote file
    if (($handle = fopen($url, "r")) !== false) {

    // Read each line
    while (($line = fgets($handle, 4096)) !== false) {

    // Output each line from the file as it is read. If needed, you could even filter the output here.
    // e.g: echo str_replace("foo", "bar", $line);
    echo $line;

    }

    fclose($handle);
    }
    else {
    // You might want to code some better error handling here.
    echo "Error: failed to open remote file\n";
    }
  12. Mark Thomson created this gist Dec 15, 2016.
    7 changes: 7 additions & 0 deletions !_import_ftp-proxy.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    Since WP All Import only supports fetching data files over HTTP or HTTPS, many users employ their own proxy script in PHP to act as an intermediary. This script would read the data file from the FTP server and output it over HTTP (for consumption by WP All Import).

    For example, you could have a PHP script on your server called `ftp-proxy.php` and then tell WP All Import to import from that URL:

    `http://example.com/ftp-proxy.php`

    Security note: Anyone could access your data if they guess this URL.We recommend either removing this file from the server after you've run your import or renaming this file to something "unguessable" (e.g. 'ftp-proxy-24dxfi3.php') but understand that method is not perfectly secure. For best security use an .htaccess rule allowing access only from localhost.
    12 changes: 12 additions & 0 deletions ftp-proxy-simple.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <?php

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment');
    header('Pragma: no-cache');

    // Fetch the file and echo it
    readfile($url);
    28 changes: 28 additions & 0 deletions ftp-proxy.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    <?php

    // These headers aren't strictly needed but can be helpful
    header('Content-Type: text/plain');
    header('Content-Disposition: attachment');
    header('Pragma: no-cache');

    // Enter the FTP (or HTTP) URL of your data file here.
    $url = "ftp://username:[email protected]/path/to/file.csv";

    // Open remote file
    if (($handle = fopen($url, "r")) !== false) {

    // Read each line
    while (($line = fgets($handle, 4096)) !== false) {

    // Output each line from the file as it is read. If needed, you could even filter the output here.
    // e.g: echo str_replace("foo", "bar", $line);
    echo $line;

    }

    fclose($handle);
    }
    else {
    // You might want to code some better error handling here.
    echo "Error: failed to open remote file\n";
    }