[solved] problem with ftp_get finding file
Posted: Sun Feb 03, 2008 11:01 am
I need to have my client creats a comma-delimited file from the database and download it. I have the process completed to the point of the file being created on the server, now I need to get it to my client and that needs to be simple to the point of "click here." Using the php ftp functionality seems the best way, but I can't seem to connect with the file on the server. The following tells me "successfully connected" and "Successfully logged in" and then and error that the file to be downloaded could not be found.
The file is there, and I've tried about 20 different pathing methods to get to it, none of which work. What am I missing, or is there some simpler way to get a file from the server to the client? (Forget setting them up with an ftp client account. They are nowhere near sophisticated enough for that.)
Code: Select all
<?php
$fil = @fopen("../support/datadump.csv","w");
if ($fil == FALSE) echo "Failed to open file...";
else
{ // stuff here to write to the file
fclose($fil);
$local_file = "datadump.csv";
$server_file = "../support/datadump.csv";
$ftp_server = "ftp.servername.com";
$ftp_user_name = "username";
$ftp_user_pass = "password";
$conn_id = ftp_connect($ftp_server);
if ($conn_id == FALSE) echo "ftp Connect error\n\n";
else
{
echo "Successfully connected\n";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if ($login_result == FALSE) echo "ftp login error\n\n";
else
{
echo "Successfully logged in\n";
if (ftp_get($conn_id, $local_file, $server_file, FTP_ASCII))
echo "Successfully written to $local_file\n";
else echo "There was a problem writing\n";
}
ftp_close($conn_id);
}
}
?>