...

View Full Version : Need Help With FTP script



hawkseye
12-30-2005, 08:09 PM
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);
}
}
}
?>

hawkseye
12-30-2005, 10:11 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum