I have several niche price comparison sites where i need to update my productlist on a regular basis. When a merchant delivers his datafeed from his webserver(http://domain.com/feed.csv) you can use php's filecopy function.

Other merchants only offer an option to fetch there datafeed from an FTP server(ie shareasale merchants). This is where the code below offers the perfect solution.

ASP:
  1. $ftp_server = "ftp.domain.com";
  2. $ftp_user_name = "";
  3. $ftp_user_pass = "";
  4.  
  5. $local_file = "download.txt"; //local path
  6. $server_file = '/del/todo.txt';//path on ftp server
  7.  
  8. $conn_id = ftp_connect($ftp_server);
  9. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  10. ftp_pasv($conn_id, TRUE);//set passive mode
  11.  
  12. if ((!$conn_id) || (!$login_result)) {
  13. echo "An error occured while connecting to $ftp_server with user: $ftp_user_name.<br />";
  14. exit;
  15. } else {
  16. echo "Connected to $ftp_server successfully with user: $ftp_user_name.<br />";
  17. }
  18.  
  19. $download = ftp_get($conn_id, $local_file , $server_file , FTP_ASCII);//the file download
  20.  
  21. if (!$download) {
  22. echo "An error occured while downloading the file";
  23. } else {
  24. echo "Download completed succesfully";
  25. }
  26.  
  27. ftp_close($conn_id);

You only whant to use the passive mode when you get an "illegal port command" error.

ASP:
  1. ftp_pasv($conn_id, TRUE);//set passive mode