kat35601 Posted September 20, 2017 Share Posted September 20, 2017 I am using ftp_get to connect to a server and want to download a file named CCDATA.TXT from a folder named Outbox. I can do this with filezilla and I can connect to the server with the below code. // test connection $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); But I get these error when I try this code. Warning: ftp_get(/Outbox/CCDATA.TXT): failed to open stream: No such file or directory in /var/www/html/dashboard/data/file_download.php on line 16Warning: ftp_get(): Error opening /Outbox/CCDATA.TXT in /var/www/html/dashboard/data/file_download.php on line 16Error downloading CCDATA.TXT. $local_file = "file.txt"; $server_file = 'CCDATA.TXT'; $ftp_username="removed"; $ftp_userpass="removed"; $ftp_path = '/Outbox/'; $ftp_server = "removed"; $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); Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2017 Share Posted September 20, 2017 Try without the leading slash: $ftp_path = 'Outbox/'; Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 Same 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 16Warning: ftp_get(): Error opening Outbox/CCDATA.TXT in /var/www/html/dashboard/data/cit_file_download.php on line 16Error downloading CCDATA.TXT.Connected as giachoufiu@tf.sftp.citonline.com Link to comment Share on other sites More sharing options...
ginerjm Posted September 20, 2017 Share Posted September 20, 2017 And remove the @ sign on your login attempt. Why oh why do people use those things..... Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 The @ came from example 1 of the php manual from here http://php.net/manual/en/function.ftp-login.php I did remove it and still connects to the server. Any idea how to get to the folder Outbox??? Thanks Link to comment Share on other sites More sharing options...
ginerjm Posted September 20, 2017 Share Posted September 20, 2017 Apparently your path and filename do not exist. Have you viewed the actual directory on that ftp server to verify things? Cases correct? Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 yes I have connected with filezilla and and see two folders inbox and outbox. Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2017 Share Posted September 20, 2017 What does print_r(ftp_nlist($ftp_con, "."));show? Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 it shows Array ( [0] => Inbox [1] => Outbox ) Connected as giajhjufiu@tf.sftp.online.com Link to comment Share on other sites More sharing options...
ginerjm Posted September 20, 2017 Share Posted September 20, 2017 Can you show us the Current set of code that is doing the get call? And before the get echo out the values that are being used in the call. All of them plz. Dare I ask if line 16 is the line we are looking at? Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 Yes line 16 is the line echo $ftp_server.$ftp_path.$server_file; tf.sftp.online.com/Outbox/CCDATA.TXT Link to comment Share on other sites More sharing options...
ginerjm Posted September 20, 2017 Share Posted September 20, 2017 I want to see the 'set of code' meaning the lines that setup this operation so I can compare what you are doing with what you think is happening. Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 This is what I have so far. <?php $local_file = "order.txt"; $server_file = 'CCDATA.TXT'; $ftp_username="removed"; $ftp_userpass="removed"; $ftp_path = '/Outbox/'; $ftp_server = "tf.sftp.online.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 echo $ftp_server.$ftp_path.$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); // test connection /* $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)) { print_r(ftp_nlist($ftp_conn, ".")); echo "Connected as $ftp_username@$ftp_server\n"; } else { echo "Couldn't connect as $ftp_username\n"; } // close the connection ftp_close($conn_id); */ ?> Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2017 Share Posted September 20, 2017 My next question is print_r(ftp_nlist($ftp_con, "./Outbox")); var_dump(is_writable(".")); Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 Array ( [0] => Inbox [1] => Outbox ) Array ( [0] => CCDATA.TXT ) bool(true) Connected as giajhojju@tf.sftp.online.com Link to comment Share on other sites More sharing options...
kat35601 Posted September 20, 2017 Author Share Posted September 20, 2017 I got it if (ftp_get($ftp_conn, $local_file, $ftp_path.$server_file, FTP_ASCII)) I reversed $local_file and $ftp_path.$server_file and it works. thank you for the input Link to comment Share on other sites More sharing options...
requinix Posted September 20, 2017 Share Posted September 20, 2017 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.