Forum Moderators: coopster

Message Too Old, No Replies

PHP FTP problem

PHP FTP problem

         

itnecor

4:02 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



I usually using the codes below to connect to FTP and display its content. It work most of the server that I'm using except on the server I'm using this time. But the more unsual to is that it works when I'am using ftp_rawlist($conn_id, '/'); but not in $buff = ftp_nlist($conn_id, ".");

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

$ftp_server = '<address>';
$ftp_username = '<username>';
$ftp_password = '<password>';

$conn_id = ftp_connect("$ftp_server");
if (!$conn_id)
die ("Unable to connect to FTP server");

$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
if (!$login_result)
die ("Unable to log in to FTP server");


$buff = ftp_nlist($conn_id, ".");
//$buff = ftp_rawlist($conn_id, '/');

foreach ($buff as $value) {
$res = ftp_size($conn_id, $value);
$extension = explode('.', "$value");
echo $value;
echo "<br />\n";
}

ftp_close($conn_id);

eelixduppy

8:50 pm on Nov 2, 2006 (gmt 0)



Could it be that your directory isn't correct? Try:

$buff = ftp_nlist($conn_id, "/");

666 posts for the third time, and I was correct, the bugs do show their ugly heads after 666 posts ;)

itnecor

3:21 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



Thanks eelixduppy!

I've tried what you said but it is still not working.

eelixduppy

10:38 pm on Nov 3, 2006 (gmt 0)



Are any errors being thrown, either to the browser or to a log file?

It doesn't make sense why this doesn't work, then...

itnecor

6:17 am on Nov 4, 2006 (gmt 0)

10+ Year Member



It displays nothing.

coopster

11:06 pm on Nov 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



var_dump [php.net] the array being returned ($buff) on the ftp_nlist function. If it comes back as boolean FALSE at least you will know whether or not you are running into an error.

itnecor

8:18 am on Nov 7, 2006 (gmt 0)

10+ Year Member



Here is the result upon doing waht you have said.

When I'm using the $buff = ftp_nlist($conn_id, "."); the output is
bool(false) .

While $buff = ftp_nlist($conn_id, "/"); gives me an output of
array(0) { } .

I think my client has a virtual directory? Am I correct with that theory?

coopster

2:25 pm on Nov 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Don't know, but at least you know now that it is returning in error. Check the logs if possible, there you may find your answer.

itnecor

2:30 pm on Nov 7, 2006 (gmt 0)

10+ Year Member



Thanks coopster for your help and time.

coopster

2:47 pm on Nov 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure, but please keep us posted, we would like to hear what you discover.

itnecor

5:29 pm on Nov 23, 2006 (gmt 0)

10+ Year Member



The IT staff of my client told me that they do not setup any virtual directory and he told me also that I do not need to connect in PASV mode.

I tried also to increase the request timeout but nothing happened. Until now I experiencing difficulty to solve this.

itnecor

6:25 pm on Nov 23, 2006 (gmt 0)

10+ Year Member



What I'm thinking now is to use DOS command with PHP exec(); function, because I tried using DOS to connect and it is working.

Is this correct?

exec("ftp <IP_address>");

>>> my problem with this one is how to include the logon info?

coopster

4:24 pm on Nov 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could specify a text file containing your FTP commands:
ftp -s:ftpinput.txt <host>

ftpinput.txt
userid 
password

But I don't see how this is going to change anything. You are already connecting with PHP, no need to exec with DOS commands. The trouble is not in the connection, but the directory argument of the PHP function being used. If root ("/") works, but not current ("."), I would expect there should be some kind of error message being returned as the function is returning a boolean FALSE value. Still interested in what is going on, so keep us posted!

itnecor

10:28 am on Nov 28, 2006 (gmt 0)

10+ Year Member



Thanks again, by the way here is the reply of my client when I asked them if they have a virtual directory.

'The directory you log into is C:\FTP\Clients\project101. Your login should take you to that directory as your root. The server seems to be working well on our end. Do you use passive transfers? if so, try logging in without passive transfers, you should not have to use them. Let me know if I can be of any further assistance.'

Does this message make sense to you?

swa66

11:17 am on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Their message makes little sense to me as it seems contradictory.

Connect manually to that ftp server, check the current directory as you log in. (The command to get the current directory in a ftp session is "pwd")

It'll tell you much more.

FWIW: there are many funny acting ftpd's for windows out there. In a worst case debug it using packet captures to know what's going back and forth on the wire.

itnecor

11:31 am on Nov 28, 2006 (gmt 0)

10+ Year Member



It says there that the currenty directory is "/". I have changed already the '.' on my program to '/' but it doesn't have an effect.
When I connect with PASV mode it give me an error of 'Warning: Invalid argument supplied for foreach() in c:\ibserver\www\auto_download\testpage.php on line 20' and when I'm connecting without a PASV mode it still displays nothing.

swa66

11:10 pm on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I said there are some weird windows based ftp daemons out there.

Parsing the result of a ls (or dir, or whatever php sends to the server) isn't going to be always easy to parse into filenames.

Test the output from that server for commands like dir and ls against a well known public ftp server. If you see it differ in output, I think you'll have found the cause.

commands I'd try:
dir .
dir /
ls .
ls /

But I'd need to check what php actually sends to the servers (I didn't read the source code, sorry).

swa66

11:13 pm on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you read [bugs.php.net...]
It seems a regressing windows problem with some "me too"-s on it ...

itnecor

8:29 am on Dec 13, 2006 (gmt 0)

10+ Year Member



Thanks swa66! I have tried what you have said and below is the result.

.....................................................
230 User logged in, proceed.
ftp> dir .
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw- 1 user group 0 Dec 12 15:51 .
drw-rw-rw- 1 user group 0 Dec 12 15:51 ..
drw-rw-rw- 1 user group 0 Sep 27 14:34 09272006
drw-rw-rw- 1 user group 0 Oct 2 15:37 10022006
drw-rw-rw- 1 user group 0 Oct 3 16:33 10032006
drw-rw-rw- 1 user group 0 Oct 4 18:48 10042006
drw-rw-rw- 1 user group 0 Oct 6 16:23 10062006
drw-rw-rw- 1 user group 0 Oct 9 21:18 10092006
drw-rw-rw- 1 user group 0 Oct 10 16:34 10102006
drw-rw-rw- 1 user group 0 Oct 17 16:39 10172006
drw-rw-rw- 1 user group 0 Oct 18 22:13 10182006
drw-rw-rw- 1 user group 0 Oct 19 08:18 10192006
drw-rw-rw- 1 user group 0 Oct 20 18:42 10202006
drw-rw-rw- 1 user group 0 Oct 23 17:00 10232006
drw-rw-rw- 1 user group 0 Oct 24 20:25 10242006
drw-rw-rw- 1 user group 0 Oct 25 15:02 10252006
drw-rw-rw- 1 user group 0 Oct 27 11:51 10272006
drw-rw-rw- 1 user group 0 Oct 31 19:45 10312006
drw-rw-rw- 1 user group 0 Nov 6 14:46 11062006
drw-rw-rw- 1 user group 0 Nov 7 16:44 11072006
drw-rw-rw- 1 user group 0 Nov 8 18:59 11082006
drw-rw-rw- 1 user group 0 Nov 9 20:09 11092006
drw-rw-rw- 1 user group 0 Nov 10 18:34 11102006
drw-rw-rw- 1 user group 0 Nov 16 22:32 11162006
drw-rw-rw- 1 user group 0 Nov 18 00:17 11182006
drw-rw-rw- 1 user group 0 Nov 22 23:57 11222006
drw-rw-rw- 1 user group 0 Nov 23 02:30 11232006
drw-rw-rw- 1 user group 0 Nov 27 18:39 11272006
drw-rw-rw- 1 user group 0 Nov 28 19:37 11282006
drw-rw-rw- 1 user group 0 Dec 2 00:10 12012006
drw-rw-rw- 1 user group 0 Dec 2 00:02 12022006
drw-rw-rw- 1 user group 0 Dec 5 18:16 12052006
drw-rw-rw- 1 user group 0 Dec 6 17:10 12062006
drw-rw-rw- 1 user group 0 Dec 8 17:34 12082006
drw-rw-rw- 1 user group 0 Dec 12 15:51 12122006
226 Transfer complete.
ftp: 2262 bytes received in 0.03Seconds 72.97Kbytes/sec.

ftp> dir /
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw- 1 user group 0 Dec 12 15:51 .
drw-rw-rw- 1 user group 0 Dec 12 15:51 ..
drw-rw-rw- 1 user group 0 Sep 27 14:34 09272006
drw-rw-rw- 1 user group 0 Oct 2 15:37 10022006
drw-rw-rw- 1 user group 0 Oct 3 16:33 10032006
drw-rw-rw- 1 user group 0 Oct 4 18:48 10042006
drw-rw-rw- 1 user group 0 Oct 6 16:23 10062006
drw-rw-rw- 1 user group 0 Oct 9 21:18 10092006
drw-rw-rw- 1 user group 0 Oct 10 16:34 10102006
drw-rw-rw- 1 user group 0 Oct 17 16:39 10172006
drw-rw-rw- 1 user group 0 Oct 18 22:13 10182006
drw-rw-rw- 1 user group 0 Oct 19 08:18 10192006
drw-rw-rw- 1 user group 0 Oct 20 18:42 10202006
drw-rw-rw- 1 user group 0 Oct 23 17:00 10232006
drw-rw-rw- 1 user group 0 Oct 24 20:25 10242006
drw-rw-rw- 1 user group 0 Oct 25 15:02 10252006
drw-rw-rw- 1 user group 0 Oct 27 11:51 10272006
drw-rw-rw- 1 user group 0 Oct 31 19:45 10312006
drw-rw-rw- 1 user group 0 Nov 6 14:46 11062006
drw-rw-rw- 1 user group 0 Nov 7 16:44 11072006
drw-rw-rw- 1 user group 0 Nov 8 18:59 11082006
drw-rw-rw- 1 user group 0 Nov 9 20:09 11092006
drw-rw-rw- 1 user group 0 Nov 10 18:34 11102006
drw-rw-rw- 1 user group 0 Nov 16 22:32 11162006
drw-rw-rw- 1 user group 0 Nov 18 00:17 11182006
drw-rw-rw- 1 user group 0 Nov 22 23:57 11222006
drw-rw-rw- 1 user group 0 Nov 23 02:30 11232006
drw-rw-rw- 1 user group 0 Nov 27 18:39 11272006
drw-rw-rw- 1 user group 0 Nov 28 19:37 11282006
drw-rw-rw- 1 user group 0 Dec 2 00:10 12012006
drw-rw-rw- 1 user group 0 Dec 2 00:02 12022006
drw-rw-rw- 1 user group 0 Dec 5 18:16 12052006
drw-rw-rw- 1 user group 0 Dec 6 17:10 12062006
drw-rw-rw- 1 user group 0 Dec 8 17:34 12082006
drw-rw-rw- 1 user group 0 Dec 12 15:51 12122006
226 Transfer complete.
ftp: 2262 bytes received in 0.19Seconds 12.10Kbytes/sec.

ftp> ls .
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
226 Transfer complete.

ftp> ls /
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
226 Transfer complete.

ftp> ls -1
200 PORT Command successful.
150 Opening ASCII mode data connection for /bin/ls.
09272006
10022006
10032006
10042006
10062006
10092006
10102006
10172006
10182006
10192006
10202006
10232006
10242006
10252006
10272006
10312006
11062006
11072006
11082006
11092006
11102006
11162006
11182006
11222006
11232006
11272006
11282006
12012006
12022006
12052006
12062006
12082006
12122006
226 Transfer complete.
ftp: 330 bytes received in 0.00Seconds 330000.00Kbytes/sec.

itnecor

8:39 am on Dec 13, 2006 (gmt 0)

10+ Year Member



swa66, with regards to the bugs stated on [bugs.php.net...] I think it is not applicable to my problem, because only
$buff = ftp_nlist($conn_id, "."); is not working while $buff = ftp_rawlist($conn_id, '.'); is working.