-1

I would like to download a file from an ftp site. I can connect to the site using this.

I get this error: Warning: ftp_get(/Outbox/CCDATA.TXT): failed to open stream: No such file or directory in /var/www/html/dashboard/data/cit_file_download.php on line 16

Warning: ftp_get(): Error opening /Outbox/CCDATA.TXT in /var/www/html/dashboard/data/cit_file_download.php on line 16 Error downloading CCDATA.TXT.

conn_id = ftp_connect($ftp_server) or die("Couldn't connect to 
$ftp_server"); 

// try to login
if (@ftp_login($conn_id, $ftp_username, $ftp_userpass)) {
echo "Connected as $ftp_username@$ftp_server\n";
} else {
echo "Couldn't connect as $ftp_username\n";
}

// close the connection
ftp_close($conn_id);  

so I know my credentials work. My trouble seems to be in adding a path. the file I need is in a folder called "Outbox" and I have not been successful with anything I have tried.

This is my current code. Thanks for the help

$local_file = "order.txt";
$server_file = 'CCDATA.TXT';
$ftp_username="removed";
$ftp_userpass="removed";
$ftp_path = '/Outbox/';
$ftp_server = "removed.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to 
$ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);



// download server file
if (ftp_get($ftp_conn, $ftp_path.$server_file, $local_file,  
FTP_ASCII))
 {
 echo "Successfully written to $local_file.";
 }
else
 {
echo "Error downloading $server_file.";
}

// close connection
ftp_close($ftp_conn);
kk4iku
  • 31
  • 6

1 Answers1

1

The local file should come first then the server file and path.

if (ftp_get($ftp_conn, $local_file, $ftp_path.$server_file,FTP_ASCII))

kk4iku
  • 31
  • 6