Skip to content

Instantly share code, notes, and snippets.

@Programmer095
Forked from m-thomson/import-ftp-proxy.php
Created August 23, 2017 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Programmer095/28a5741cbd126f6f3eadbc360c1bdcf6 to your computer and use it in GitHub Desktop.
Save Programmer095/28a5741cbd126f6f3eadbc360c1bdcf6 to your computer and use it in GitHub Desktop.
This script reads the specified file over FTP and outputs it over HTTP. Thus, you can point WP ALL Import at the URL for this script on your server to provide a "bridge" between FTP and HTTP. This is provided with the hope it will be useful but custom PHP and importing over FTP is not officially supported.
<?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 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:password@hostname.com/full/path/to/file.csv";
// These headers aren't strictly needed but can be helpful
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="ftp-proxy-data.txt"');
header('Pragma: no-cache');
// Fetch the file and echo it
readfile($url);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment