« Apache httpd , browser, MySQL and MySQL client downloads | Main | Train and business balls all in the air! »

March 01, 2007

Sample script - FTP to get a file from within PHP

A worked example from today's course - Only the password has been changed

<?php
$conn_id = ftp_connect("www.savethetrain.org.uk");
$login_result = ftp_login($conn_id, "savethetrain", "melksham");

if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
exit;
} else {
echo "Connected";
}

// get the file
$local = fopen("local.txt","w");
$result = ftp_fget($conn_id, $local,"httpdocs/trlog.txt", FTP_BINARY);

// check upload status
if (!$result) {
echo "FTP download has failed!";
} else {
echo "Downloaded ";
}

// close the FTP stream
ftp_close($conn_id);
?>

Posted by gje at March 1, 2007 02:41 PM

Comments

Post a comment




Remember Me?


Well House Consultants Ltd. Copyright 2008