Hi, I am a beginner when it comes to php and am wondering if any one can help me with some errors i am getting.
I have a download script that access a Mysql DB and gets the relevant information like ip, port, ftp access name and pwd.
Currently there are about 20 entries in the DB but not all require ftp access for downloading.
Here is the script for downloading the files.
<?php
// Databse login information
include ("include_db_access.php");
// get latest file from database
$sql = "SELECT * FROM `ldr_config` ";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
$db_file = $newArray['file_no'];
$ftp_server = $newArray['ftp_access'];
$ftp_port = $newArray['ftp_port'];
$ftp_user_name = $newArray['ftp_user'];
$ftp_user_pass = $newArray['ftp_pwd'];
$local_server_path = $newArray['local_folder'];
$remote_server_path = $newArray['remote_folder'];
// check to see if server has no ftp
if ($ftp_server == "") {
$no_server = "yes";
}
if ($no_server != "yes") {
// convert into correct file structure.
$display_file = str_pad($db_file, 8 , "0", STR_PAD_LEFT);
$logfile = str_pad($display_file, 12 , ".log");
// $local_server_name is the folder where we are storing the .log files
$local_server_name = $local_server_path;
$local_file .= $local_server_name;
$local_file .= $logfile;
// remote folder path this can be changed if required
$remote_file = $logfile;
// Get last file on remote server so we know when to stop downloading files.
// set up ftp connection
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, false);
$buff = ftp_rawlist($conn_id, $remote_server_path, TRUE);
// output the buffer
$file_last = var_export($buff, true);
$last_file = substr("$file_last", -16, -; // month value
$logfile = $display_file;
// Start downloading files and save them to $local_file location and also change directory path on remote server
if ($remote_server_path != "") {
if (ftp_chdir($conn_id, $remote_server_path)) {
} else {
echo "Couldn't change directory\n";
}
}
while ( $logfile < $last_file ) {
$handle = fopen($local_file, 'w');
// try to download $remote_file and save it to $handle
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
echo "$remote_file has sucessfully been saved to $local_file <br>";
} else {
echo "file $remote_file does note exists\n";
}
// increment file and continue download
fclose($handle);
$db_file = $display_file + 1;
$display_file = str_pad($db_file, 8 , "0", STR_PAD_LEFT);
$logfile = str_pad($display_file, 12 , ".log");
// reset some values so they dont duplicate
$local_file = "";
$remote_file = $logfile;
$local_server_name = $local_server_path;
$local_file .= $local_server_name;
$local_file .= $logfile;
}
// close the connection and the file handler
ftp_close($conn_id);
} // end if for no server
$local_file = "";
$remote_file = "";
$file_last = "";
$last_file = "";
$display_file = "";
$no_server = "";
echo "<br>";
}
Here is an example of the error I am getting.
PHP Warning: ftp_login() expects parameter 1 to be resource, boolean given in down.php on line 73
PHP Warning: ftp_pasv() expects parameter 1 to be resource, boolean given in down.php on line 74
PHP Warning: ftp_rawlist() expects parameter 1 to be resource, boolean given in down.php on line 75
PHP Warning: ftp_chdir() expects parameter 1 to be resource, boolean given in down.php on line 91
PHP Warning: ftp_close() expects parameter 1 to be resource, boolean given in down.php on line 130
Thanks in advance