Created
April 14, 2015 19:50
-
-
Save shabdar/b1d4dc87c7034dc07641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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