Skip to content

Instantly share code, notes, and snippets.

@shabdar
Created April 14, 2015 19:50
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 shabdar/b1d4dc87c7034dc07641 to your computer and use it in GitHub Desktop.
Save shabdar/b1d4dc87c7034dc07641 to your computer and use it in GitHub Desktop.
<?php
//ftp server information
//change values to reflect you server settings
$ftp_server = "ftp.yoursite.com";
$ftp_username = "username";
$ftp_password = "password";
$server_file = "/path_to_csv_file/inventory.csv";
$local_file = "inventory.csv";
//connect to ftp server
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_password);
//download the csv file to local folder
if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII)) {
//load the contents of downloaded csv file
$file_contents = file_get_contents($local_file);
} else {
//set an error message if ftp_get fails
$file_contents = "Error downloading $server_file.";
}
//close ftp connection
ftp_close($ftp_conn);
//send the contents of the csv file (or the error message) to standard output
header('Content-Type: text/plain');
echo $file_contents;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment