DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

FTP To Get A File From Within PHP

03.03.2007
| 2565 views |
  • submit to reddit
        
$conn_id = ftp_connect("www.yoursite.com");
$login_result = ftp_login($conn_id, "username", "password");

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);