file

Import an external file

file_save_data does (almost) all the job for us and drupal_http_request allows to get the file even through a proxy.

Create a csv file

this is php code using Drupal file stream