Vote count:
0
I am trying to run a php script to transfer my mysql file to an external server. The error i'm getting is: Warning: ftp_chdir() expects parameter 1 to be resource, boolean given
Here is my code:
<?php
// Set Timezone
date_default_timezone_set('America/Los_Angeles');
// location of your temp directory
$tmpDir = "/tmp/";
// username for MySQL
$user = "myusername";
// password for MySQL
$password = "mypassword";
// database name to backup
$dbName = "mydbname";
// hostname or IP where database resides
$dbHost = "xx.xx.xx.xx";
// the zip file sent to you will have this prefixed
$prefix = "mysqlbackup_";
// Destination folder
$dest = "/CompanyName/Websites/trik11/_db_backups";
$ftp_server = "24.10.0.246";
$ftp_port = "21";
$ftp_user = "savepro";
$ftp_pass = "Michigan2364!";
// Create the database backup file
$sqlFile = $tmpDir.$prefix.date('m-d-Y_h-i').".sql";
$backupFilename = $prefix.date('m-d-Y_h-i').".tgz";
$backupFile = $tmpDir.$backupFilename;
$createBackup = "mysqldump -h ".$dbHost." -u ".$user." --password='".$password."' ".$dbName." > ".$sqlFile;
$createZip = "tar cvzf $backupFile $sqlFile";
exec($createBackup);
exec($createZip);
$conn_id = ftp_connect($ftp_server, $ftp_port);
// try to login
@ftp_login($conn_id, $ftp_user, $ftp_pass)
// change directory
ftp_chdir($conn_id, $dest);
// turn passive mode on
ftp_pasv($conn_id, true);
// put files up
ftp_put($conn_id, $backupFilename, $backupFile, FTP_BINARY)
// Delete the temporary files
unlink($sqlFile);
unlink($backupFile);
// close the connection
ftp_close($conn_id);
?>
Based off of what I read it is something to do with my path, but my path is accurate so I'm not sure what exactly it could be.
asked 33 secs ago
Aucun commentaire:
Enregistrer un commentaire