Advertisement
Guest User

Untitled

a guest
May 25th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. //ftp server information
  4. //change values to reflect you server settings
  5. $ftp_server = "ftp.yoursite.com";
  6. $ftp_username = "username";
  7. $ftp_password = "password";
  8.  
  9. $server_file = "/path_to_csv_file/inventory.csv";
  10. $local_file = "inventory.csv";
  11.  
  12. //connect to ftp server
  13. $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  14. $login = ftp_login($ftp_conn, $ftp_username, $ftp_password);
  15.  
  16. //download the csv file to local folder
  17. if (ftp_get($ftp_conn, $local_file, $server_file, FTP_ASCII)) {
  18. //load the contents of downloaded csv file
  19. $file_contents = file_get_contents($local_file);
  20. } else {
  21. //set an error message if ftp_get fails
  22. $file_contents = "Error downloading $server_file.";
  23. }
  24.  
  25. //close ftp connection
  26. ftp_close($ftp_conn);
  27.  
  28. //send the contents of the csv file (or the error message) to standard output
  29. header('Content-Type: text/plain');
  30. echo $file_contents;
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement