mintuz
mintuz

Reputation: 721

remote server FTP php script server to server

Hi got a few issues with a backup script I am making, it is outputting a few errors. The purpose of this script is to backup a mysql file, save it to the local server but also upload it to a remote server. Thanks

Warning: ftp_login() [function.ftp-login]: Login authentication failed ... line 123

Warning: ftp_chdir() [function.ftp-chdir]: You aren't logged in in ... line 125

Warning: ftp_fput() [function.ftp-fput]: You aren't logged in in ... line 127

//***********SAVE FILE***********
      $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); //db-backup-time-md5hash.sql ( opens for reading and writing )
      fwrite($handle,$content); //copy content over to open file
      fclose($handle); //close the file

  // open some file for reading
$file = 'db-backup-1322909178-07f410c05ec2f736364667e1febd105f.sql';
$fp = fopen($file, 'r');

$ftp_server = "REMOTE SERVER";
$ftp_user_name = "REMOTE USER";
$ftp_user_password = "REMOTE PASS";
$rempath = "/public_html/";

// set up basic connection
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

ftp_chdir($conn_id, $rempath);

// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "Successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);

Upvotes: 0

Views: 788

Answers (1)

ajreal
ajreal

Reputation: 47321

There is a typo in this line :-

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$ftp_user_pass is no defined in your script :-

$ftp_user_password <-- what was defined
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

If this helped, make sure you don't bang your head into the wall

Upvotes: 1

Related Questions