Here is the Code I am using for the same function with more flexibility in static code:
$name = "FILE NAME";
$filename = "FILE NAME WITH FULL PATH";
//-- Code to Transfer File on Server Dt: 06-03-2008 by Aditya Bhatt --//
//-- Connection Settings
$ftp_server = "IP ADDRESS"; // Address of FTP server.
$ftp_user_name = " SERVER USERNAME"; // Username
$ftp_user_pass = " SERVER PASSWORD"; // Password
$destination_file = " SERVER FILE PATH TO UPLOAD VIA FTP_PUT"; //where you want to throw the file on the webserver (relative to your login dir)
$conn_id = ftp_connect($ftp_server) or die("
Couldn't connect to $ftp_server
"); // set up basic connection$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("
You do not have access to this ftp server!
"); // login with username and password, or give invalid user messageif ((!$conn_id) || (!$login_result)) { // check connection
// wont ever hit this, b/c of the die call on ftp_login
echo "
FTP connection has failed!
";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name
";
}
$upload = ftp_put($conn_id, $destination_file.$name, $filename, FTP_BINARY); // upload the file
if (!$upload) { // check upload status
echo "
FTP upload of $filename has failed!
";
} else {
echo "
Uploading $name Completed Successfully!
";
}
ftp_close($conn_id); // close the FTP stream
?>