Do you have to connect and login every time you run a script with ftp function.

I tried to store the connection id in a session, but that did not work.

I tested it with this script:

session_start();

if(isset($_SESSION['conn_id'])){
	echo ftp_pwd($_SESSION['conn_id']);
}else{
	$conn_id = ftp_connect("host");
	$login = ftp_login($conn_id, "user", "pass");
	$_SESSION['conn_id'] = $conn_id;
	echo ftp_pwd($conn_id);
}

When I reload the page I get this error:
Warning: ftp_pwd() expects parameter 1 to be resource, integer given in C:\server\test.php on line 5

    I'd say yes, as PHP doesnt appear to cater to such persistent connections.

    Once the script is done, PHP will probably close the connection if the script hasnt already done so, and so the resource would then be invalid.

      Seems like you are right.

      Thanks a lot 4 all your help laserlight 🙂

        Write a Reply...