Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/53033-using-fopen-in-an-ftp-connection/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.