Strange rawlist behaviour
Strange rawlist behaviour
am 07.02.2006 07:52:26 von Chris Payne
------=_NextPart_000_0004_01C62B89.25C1F560
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi there everyone,
Can anyone see a problem with the below code? It scans an FTP directory and
adds the LAST item in that directory to the database (Being the latest item
added) - however, if the directory only has 1 file in it it WON'T add
anything, the system returns that the directory is empty and it's very
frustrating.
chris
$conn_id = ftp_connect($ftp_server2);
$login_result = ftp_login($conn_id, $ftp_user_name2, $ftp_user_pass2);
// check connection
if ((!$conn_id) || (!$login_result)) {
die("FTP connection has failed !");
};
// Initiate passive mode
if (ftp_pasv($conn_id, true))
{ echo ""; }
else { echo "Could not initiated passive mode
"; }
// try to change the directory to somedir
if (ftp_chdir($conn_id, "$newdir2")) {
// echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
// get the file list for /
$array = ftp_rawlist($conn_id, "-t");
$newdata = $contents[0];
for ( $i = 1; $i < count($array); $i++ ) {
$current = $array[$i];
$structure[$i]['name'] = substr($current, 55, strlen($current) - 0);
$newdatab = $structure[$i][name];
}};
// close the connection
ftp_close($conn_id);
};
------=_NextPart_000_0004_01C62B89.25C1F560--
RE: Strange rawlist behaviour
am 07.02.2006 15:09:51 von Bastien Koert
$newdata = $contents[0];
for ( $i = 1; $i < count($array); $i++ ) {
$current = $array[$i];
$structure[$i]['name'] = substr($current, 55, strlen($current) - 0);
}
Should the array loop thru start at 0 (below)? Not 1 as you have the
starting value for $i (above)
$newdata = $contents[0];
for ( $i = 0; $i < count($array); $i++ ) {
$current = $array[$i];
$structure[$i]['name'] = substr($current, 55, strlen($current) - 0);
Bastien
>From: "Chris Payne"
>To:
>Subject: [PHP-DB] Strange rawlist behaviour
>Date: Tue, 7 Feb 2006 01:52:26 -0500
>
>Hi there everyone,
>
>Can anyone see a problem with the below code? It scans an FTP directory
>and
>adds the LAST item in that directory to the database (Being the latest item
>added) - however, if the directory only has 1 file in it it WON'T add
>anything, the system returns that the directory is empty and it's very
>frustrating.
>
>chris
>
> $conn_id = ftp_connect($ftp_server2);
> $login_result = ftp_login($conn_id, $ftp_user_name2, $ftp_user_pass2);
>
>// check connection
>if ((!$conn_id) || (!$login_result)) {
> die("FTP connection has failed !");
>};
>
>// Initiate passive mode
>if (ftp_pasv($conn_id, true))
>{ echo ""; }
>else { echo "Could not initiated passive mode
"; }
>
>// try to change the directory to somedir
>if (ftp_chdir($conn_id, "$newdir2")) {
>// echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
>
>// get the file list for /
>$array = ftp_rawlist($conn_id, "-t");
>
>$newdata = $contents[0];
>
> for ( $i = 1; $i < count($array); $i++ ) {
>
> $current = $array[$i];
> $structure[$i]['name'] = substr($current, 55, strlen($current) -
>0);
>
>$newdatab = $structure[$i][name];
>
> }};
>
> // close the connection
>ftp_close($conn_id);
>
>};
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Strange rawlist behaviour
am 07.02.2006 15:51:41 von Dwight Altman
I didn't read all your code, but this jumped out to me also as to Bastien
for ( $i = 1; $i < count($array); $i++ ) {
If you have 1 file, then you probably have "1 < 1" which does not execute
even once. I definitely suggest also "$i = 0;...".
-Dwight
-----Original Message-----
From: Chris Payne [mailto:chris@artistwd.com]
Sent: Tuesday, February 07, 2006 12:52 AM
To: php-db@lists.php.net
Subject: [PHP-DB] Strange rawlist behaviour
Hi there everyone,
Can anyone see a problem with the below code? It scans an FTP directory and
adds the LAST item in that directory to the database (Being the latest item
added) - however, if the directory only has 1 file in it it WON'T add
anything, the system returns that the directory is empty and it's very
frustrating.
chris
$conn_id = ftp_connect($ftp_server2);
$login_result = ftp_login($conn_id, $ftp_user_name2, $ftp_user_pass2);
// check connection
if ((!$conn_id) || (!$login_result)) {
die("FTP connection has failed !");
};
// Initiate passive mode
if (ftp_pasv($conn_id, true))
{ echo ""; }
else { echo "Could not initiated passive mode
"; }
// try to change the directory to somedir
if (ftp_chdir($conn_id, "$newdir2")) {
// echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
// get the file list for /
$array = ftp_rawlist($conn_id, "-t");
$newdata = $contents[0];
for ( $i = 1; $i < count($array); $i++ ) {
$current = $array[$i];
$structure[$i]['name'] = substr($current, 55, strlen($current) - 0);
$newdatab = $structure[$i][name];
}};
// close the connection
ftp_close($conn_id);
};
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php