hsbsid
hsbsid

Reputation: 331

Filezilla server immediately disconnects from PHP, but works perfectly fine through cmd

When I connect to my server from cmd, the filezilla server client (from xampp) shows that I am connected, then I can log in and run any commands. When I do this from PHP, using ftp_connect(), it works and the "or die ('Couldn't connect to server')" doesn't run, and it even shows up in the client window. But the window also shows that it immediately disconnects, within the same second too. Which is why I get the error:

Warning: ftp_login() expects parameter 1 to be resource, boolean given in C:\XAMMP\htdocs\PHPBook\ftp.php on line 3

I'd be great if someone could help me figure this out. Thanks in advance!

Upvotes: 0

Views: 324

Answers (1)

hsbsid
hsbsid

Reputation: 331

I just solved my problem. Sorry for not posting my code as well.

My php connect line looked like this:

$cnct = ftp_connect("localhost") || die ("Can't connect to server");

Instead of:

$cnct = ftp_connect("localhost") or die ("Can't connect to server");

Since "||" has greater precedence than "or", I guess using "||" resulted in both the connection, but also the die() to execute (although the message didnt show and the rest of the script ran after the die). It works with "or".

Upvotes: 1

Related Questions