Wget FTP CSV Datafeed Import Script

By Hawkee on Mar 10, 2005

This will download a datafeed to your server from the given FTP account. This only supports CSV datafeeds and requires a minor tweak to accomodate any other type of datafeed. It also requires that you have wget installed on your server. The user executing this script needs to have write access to the "datafeeds" folder.

This can be used in conjunction with my PHP gunzip, unzip File Extractor

Note: "wget -P db" means to put the file in the /db directory. You'll need to create it or change that parameter to match your system.

<?php

$login = 'login';
$password = 'password';
$server = 'ftp.merchant.com';
$datafeed_file = "datafeed.csv";

unlink("datafeeds/$datafeed_file");
$path = "wget -P db ftp://$login:$password@$server/datafeed/$datafeed_file";
`$path`;

$datafeed = "datafeeds/$datafeed_file";
$fp = fopen($datafeed, 'r');

while($data = fgetcsv($fp, 3000))
{
    $sku = $data[0];
    $name = addslashes(preg_replace("/"/", '', $data[1]));

    // And so on...
}

?>

Comments

Sign in to comment.
affordit   -  Feb 20, 2011

Is there a way to get this script or one like it to loop thru a directory of .txt.gz files and unzip and upload them to a database. I have a lot of them to do and excel takes to long.

 Respond  
Hawkee   -  Mar 12, 2005

I\'ve never needed to install wget, it\'s always installed. This is acting as an example for using wget.

 Respond  
tye   -  Mar 11, 2005

wget is almost universally installed on Linux and BSD servers. It won\'t work on Windows, however.

 Respond  
log2   -  Mar 11, 2005

sorry Hawkee, I must give you a five :( this is a good script but it requires you to have other things like wget installed on your server... that\'s just not what people are looking for, but instead of 0 i gave you a five because it\'s a very useful code if you have wget :D

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.