Skip to content

Instantly share code, notes, and snippets.

@trey8611
Last active January 18, 2019 19:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trey8611/a70075e74800b54813154410abaa0b7c to your computer and use it in GitHub Desktop.
Save trey8611/a70075e74800b54813154410abaa0b7c to your computer and use it in GitHub Desktop.
#proxyscript
<?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.
###############################################################
Instructions:
* Copy the code below to a new php file in the root of your WP site
* Update the FTP server details
* Update the $local_file variable (may need to change .csv to .xml)
* Update the $server_file (path and may need to change .csv to .xml)
* Call the new PHP file when using Download from URL: http://example.com/my_proxy_file.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 );
?>
@xmixmaster
Copy link

Where shall i place this on my site to work ?

@TurnKeyMSP
Copy link

I get "Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/to/site/ on line 8" when trying to run this script. I am trying to connect to an XML data feed, download the feed, and leave now, but having the worst trouble opening a connection to this one URL (not a ".xml" file type / address / ending). Any advice is much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment