Skip to content

Instantly share code, notes, and snippets.

@KittenCodes
Forked from Programmer095/data_feed.php
Last active May 2, 2019 14:10
Show Gist options
  • Save KittenCodes/a18c05406327c9e99764cb83cdd5b3d4 to your computer and use it in GitHub Desktop.
Save KittenCodes/a18c05406327c9e99764cb83cdd5b3d4 to your computer and use it in GitHub Desktop.
<?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 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment