How To : Google Base XML Feed Auto-Submission
I had a mildly tough time with getting my feeds sent to Google Base on a nightly schedule without doing it manually. I went through trying to use the Zend API tool, and just kept getting stuck. I then realized it was far easier to create my feed and FTP it to Google using crontab. Like anything else, if I had a problem, I’m sure someone else did as well, so I of course want to share my information.
- Step 1: Setup your feed according to Google Base specifications. Use this 5 step wizard for your feed-type.
- Step 2: Register for a Google Base account if you don’t have one already.
- Step 3: Upload and test your feed. Wait up to 24 hours for processing the feed. Then check for errors, and fix if you find any.
- Step 4: Creat an FTP account with Google by clicking “sign up” in the lower right portion of the Account Management page of Google Base. This link may work for you:
- Step 5: Create a PHP file that FTP’s your feed to Google. Code is below.
- Step 6: Create a cronjob to run that PHP file on a regular schedule. I used the following cronjob to make it run at 1:30 AM everyday.
30 01 * * * /usr/local/bin/curl http://www.mysite.com/googfeed/ftp.php
PHP Code for FTP’ing to Google
$host = "uploads.google.com";
$ftp_user_name = "INSERT YOUR GOOGLE FTP USERNAME"; //this does not equal your Google Account username.
$ftp_user_pass = "INSERT YOUR GOOGLE FTP PASSWORD"; //again not equal to Google Account password.
$remote_file = "google-base.xml"; //Change this to match the exact name of the file you setup in Google Base as your upload file.
$file = "/usr/home/htdocs/feed/google-base.xml"; // This need to be the full path to the filey ou want to send to google.
// setup $host and $file variables for your setup before here...
$hostip = gethostbyname($host);
$conn_id = ftp_connect($hostip);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// IMPORTANT!!! turn passive mode on
ftp_pasv ( $conn_id, true );
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $host for user $ftp_user_name";
die;
} else {
echo "Connected to $host, for user $ftp_user_name
";
echo "Host IP is $hostip
";
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
echo "successfully uploaded $file
";
} else {
echo "There was a problem while uploading $file
";
}
// close the connection
ftp_close($conn_id);
}
?>
#1 "website management" business for over 4+ years on...
Hi!
Thanks for the code.
I have implemented it as it is after changing required parameters. It is working on my local system successfully, failed to connect from online website hosted on BlueHost servers.
Got the error message as below:
Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/recybert/public_html/contogoogle.php on line 14
Warning: ftp_pasv() expects parameter 1 to be resource, boolean given in /home/recybert/public_html/contogoogle.php on line 17
FTP connection has failed!Attempted to connect to uploads.google.com for user recybertools
Please help me!
Thanks!
From what I’ve found, I’m thinking that Google will allow one connection per username, and maybe you didn’t disconnect the one on your local machine before trying one on your Bluehost server. Or possibly your Bluehost server has a timeout setup that won’t work. Try it a few times spaced apart by 10 – 60 minutes, and see if that helps.
I’m not sure you can help me here, as I’m grasping at straws to be honest.
function uploadThroughFTP() {
global $mosConfig_absolute_path;
$host = ‘http://ftp.uploads.google.com';
$username = $this->params['username'];
$password = $this->params['password'];
$ftpstream = ftp_connect( $host );
$login = ftp_login( $ftpstream, $username, $password );
if ( $login ) {
foreach ( $this->_upload as $type ) {
$dir = $mosConfig_absolute_path . ‘/mambots/system/froogle/’;
$file_name = “{$type}_products.xml”;
ftp_put( $ftpstream, $file_name, $dir . $file_name, FTP_ASCII );
}
}
ftp_close( $ftpstream );
}
I know you cant see the rest of the code, making it more difficult, but can you see any reason why it keeps throwing the error
Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/xxxxxx/public_html/store/mambots/system/froogle.php on line 0
It works perfect on 12 other sites, and this one just doesn’t want to know.
Many thanks
Ian
This is a connection problem, and the connection is returning false. The script should be updated to include some type of…
IF (Connect = true)
…statement, but it will be some time before I can update it. If you update and fix it, please let me know and I’ll post the edited code.
$host = ‘http://ftp.uploads.google.com’;
shouldn’t it just be
$host = ‘uploads.google.com’;
Thanks Kevin. Did you try that and it worked?