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
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Programmer095/2cdf89553f1eb286742387aa617520a0 to your computer and use it in GitHub Desktop.
Save Programmer095/2cdf89553f1eb286742387aa617520a0 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.
###############################################################
*/
$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