rhyspaterson Posted May 26, 2007 Share Posted May 26, 2007 Hey guys, Just a little script i'm writing. I know it's longer than it should be but for the moment i'm just trying to debug what's going on. Here's the code // set up FTP variables $ftp_server = "xxx.xxx.xxx.xxx"; $ftp_user_name = "xxxxx"; $ftp_user_pass = "xxxxxxxxx"; $destination = "/xxx/xxx/xxx/xxx/$registrationID/"; // 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); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!<br />"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name<br />"; } // enable passive mode ftp_pasv($conn_id, true); // change to the users directory ftp_chdir($conn_id, $destination); echo "we are now in ftp_pwd($conn_id) <br />"; // get the contents of the current directory and place them in an array. If the bbb.txt file exists, the array would output [0]=> string(10) "aaa.txt" [1]=> string(12) "bbb.txt". $contents = ftp_nlist($conn_id, "."); echo "the contents of ftp_pwd($conn_id) are "; var_dump($contents); echo "<br />"; // we must then search the array for the existence of the key bbb.txt [1]. $key = array_search('bbb.txt', $contents); // If key == 1, then bbb.txt exists. if ($key == 1){ echo "The file exists!"; // Open the file $fh = fopen($destination . 'bbb.txt', 'r') or die("Can't open file " . $destination . "bbb.txt"); // close the file fclose($fh); }else{ echo "The file doesn't exist!"; exit(); } // close the FTP stream ftp_close($conn_id); The problem is, even though the file exists and i have full RWX permissions, i still cant open it. The script stops at or die("Can't open file " . $destination . "bbb.txt"); Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/53033-using-fopen-in-an-ftp-connection/ Share on other sites More sharing options...
rhyspaterson Posted May 26, 2007 Author Share Posted May 26, 2007 Ok figured out what was happening. The fopen command is being run on the local machine, not the one i have an FTP connection with. Does anyone know how to make this command open the file on the remote FTP machine instead of the local one? Quote Link to comment https://forums.phpfreaks.com/topic/53033-using-fopen-in-an-ftp-connection/#findComment-261977 Share on other sites More sharing options...
rhyspaterson Posted May 26, 2007 Author Share Posted May 26, 2007 Ok fixed. Just used fget and wrote it locally. /dunno where solved button is Quote Link to comment https://forums.phpfreaks.com/topic/53033-using-fopen-in-an-ftp-connection/#findComment-261981 Share on other sites More sharing options...
chigley Posted May 26, 2007 Share Posted May 26, 2007 Bottom left. Quote Link to comment https://forums.phpfreaks.com/topic/53033-using-fopen-in-an-ftp-connection/#findComment-261996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.