Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help With FTP script

    I have written a sript in php which downloads all files and folders from a folder at remote server to a folder at my local server. The script would run from my local Server. The first few passes go ok. but when the script return back to the root (the folder it started from) and starts to copy files from there it gives error No such file or directory. The output of paths r ok. Cant figure out whats wrong. Please help me.


    <?php
    $NORMLS_SERVER = "Remote Server";
    $ftpDirPath = "/Remote Folder/";
    $localPath = "Local Folder";

    //connecting to normls server
    if(! $ftp = ftp_connect($NORMLS_SERVER))
    {
    fwrite($error_log, "Couldnt Connect to NORMLS SERVER .... update data ABORTED !");
    die("Couldnt Connect to NORMLS SERVER .... update data ABORTED !");
    }
    //logging in

    if(! ftp_login($ftp, "user", "password"))
    {
    fwrite($error_log, "Couldn't Log in to the NORMLS server ! ... update data ABORTED !");
    die("Couldn't Log in to the NORMLS server ! ... update data ABORTED !");
    }

    allFilesNFolders($ftp, $ftpDirPath, $localPath);

    function allFilesNFolders($ftp, $ftpDirPath, $localPath){
    ftp_chdir($ftp, $ftpDirPath);
    $contents = ftp_nlist($ftp, ".");
    for($i = 0; $i < count($contents); $i++)
    {
    $path = $localPath . "/" . $contents[$i];
    echo "<br>" . $path;
    echo "<br>" . $ftpDirPath;
    $tmp = explode(".", $contents[$i]);
    if (count($tmp) == 1){
    mkdir($path, 0777) or die("Directory create function failed !! ... ABORTING !!");
    allFilesNFolders($ftp, $ftpDirPath . $contents[$i], $path);
    }
    else{
    $fpPic = fopen($path, "w");
    ftp_fget ($ftp, $fpPic, $contents[$i], FTP_BINARY);
    fclose($fpPic);
    }
    }
    }
    ?>

  • #2
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Figured out what was wrong


    function allFilesNFolders($ftp, $ftpDirPath, $localPath){
    ftp_chdir($ftp, $ftpDirPath);
    $contents = ftp_nlist($ftp, ".");
    for($i = 0; $i < count($contents); $i++)
    {
    $path = $localPath . "/" . $contents[$i];
    $remotePath = $ftpDirPath . "/" . $contents[$i];

    $tmp = explode(".", $contents[$i]);
    if (count($tmp) == 1){
    mkdir($path, 0777) or die("Directory create function failed !! ... ABORTING !!");
    allFilesNFolders($ftp, $remotePath, $path);
    }
    else{
    $fpPic = fopen($path, "w");
    ftp_fget ($ftp, $fpPic, $remotePath, FTP_BINARY);
    fclose($fpPic);
    }
    }
    }


    The problem was in remote path when it returned to the root directory after saving all the files.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •