PHP ftp_get是递归的

I'm having some difficulty getting recursion to work in this function:

function fetchFiles($src_dir, $dst_dir) {
  global $conn_id;

  $src_dir = rtrim($src_dir, '/');
  $dst_dir = rtrim($dst_dir, '/');

  echo "fetching $src_dir into $dst_dir<br>";

  if(!is_dir($dst_dir)){
    mkdir($dst_dir);
    echo "create dir <b><u> $dst_dir </u></b><br>";
  } else echo "dir exists<br>";

  ftp_chdir($conn_id, $src_dir);
  $contents = ftp_nlist($conn_id, '.');
  foreach($contents as $file) {
    if ($file != "." && $file != "..") {
      if (is_dir($file)) {
        echo "fetch directory ".$src_dir."/".$file."<br>";
        fetchFiles($src_dir."/".$file, $dst_dir."/".$file);
      } else {
        ftp_get($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY);
        echo "create files::: <b><u>".$dst_dir."/".$file ." </u></b><br>";
      }
    }
    ob_flush();
    flush();
  }
}

I'm calling it like this:

$uploads = "/web/content/wp-content/uploads/";
$local_base = "../wp-content/uploads/";
fetchFiles($uploads, $local_base);

The uploads directory has a lot of files, which transfer without any problem. There is a folder named '2011', which gets created, as well. The folders within '2011', however, are detected as files. The output says:

create files::: /web/content/wp-content/uploads/2011/02
create files::: /web/content/wp-content/uploads/2011/10
create files::: /web/content/wp-content/uploads/2011/12

'02', '10', and '12' are all subdirectories, with files inside them. Why is it not detecting them as directories in the is_dir() check? What am I missing?

Following Marc's advice, I was able to resolve this by using the following:

if (@ftp_chdir($conn_id, $file)) { ... }

Thank you Marc!