Alright, I think I have this working for the most part but I'm getting an error. This is the code I'm using:
<?php
$ftp_host = "ftp.mysite.com";
$ftp_user = "myusername";
$ftp_password = "mypassword";
$directory = "cdr";
$ftp_server = "ftp.mysite.com";
$ftp_user_name = "myusername";
$ftp_user_pass = "mypassword";
$conn_id = "historyfiles";
//Connect
echo "<br />Connecting to $ftp_host via FTP...";
$conn = ftp_connect($ftp_host);
$login = ftp_login($conn, $ftp_user, $ftp_password);
//
//Enable PASV ( Note: must be done after ftp_login() )
//
$mode = ftp_pasv($conn, TRUE);
//Login OK ?
if ((!$conn) || (!$login) || (!$mode)) {
die("FTP connection has failed !");
}
echo "<br />Login Ok.<br />";
//
//Now run ftp_nlist()
//
$file_list = ftp_nlist($conn, "cdr");
foreach ($file_list as $file)
// define some variables
$local_file = "testtextfile.txt";
$server_file = "$file";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>
PHP is giving me this error, any ideas ?
NOTE: 41050627.txt is one of the files on the FTP site
Warning: ftp_get: '41050627.txt' : No Such File. in /home/webadmin/securetrans.wirelessprocessing.net/html/testfiles/test.php on line 50
There was a problem