<?php
function copyviaftprecursively ($uploadLocation, $previewPath, $remoteDirectory, $ftpType)
{
$errorMessage = ';
$connectionId = GetFtpConnection ($uploadLocation [' Host '], $uploadLocation [' username '], $uploadLocation [' Password '] , $uploadLocation [' Port ']);
Switch ($ftpType)
{
Case ' active ':
FTP_PASV ($connectionId, False);
Break
Case ' passive ':
FTP_PASV ($connectionId, True);
Break
}
$baseDirectory = $uploadLocation [' basedirectory '];
if (substr ($baseDirectory, strlen ($baseDirectory)-1, 1)!=]
& nbsp; {
$baseDirectory. = '/';
}
Ftp_mkdir ($connectionId, $baseDirectory);//No point showing an error Message if the directory exists (most likely cause of error) because it'll exist (at least) after the "the".
$remoteBaseDirectory = $baseDirectory. $remoteDirectory;
if (substr ($remoteBaseDirectory, strlen ($remoteBaseDirectory)-1, 1) = = '/')
{
$remoteBaseDirectory = substr ($remoteBaseDirectory, 0, strlen ($remoteBaseDirectory)-1);
}
$remoteBaseDirectory. = '/';
$errorMessage. = Copyfileviaftp ($previewPath, $remoteBaseDirectory, $connectionId);
Ftp_close ($CONNECTIONID);
$errorHtml = ';
if ($errorMessage)
{
$errorHtml = NL2BR ($errorMessage);
}
return $errorHtml;
}
function GetFtpConnection ($host, $username, $password, $port)
{
$connectionId = Ftp_connect ($host);
if (! @ftp_login ($connectionId, $username, $password))
{
WebServiceError (' FTP error. Unable to connect to "'. $host. '," "with username" '. $username. ' ");
}
return $connectionId;
}
function Copyfileviaftp ($sourcePath, $destinationPath, $connectionId)
{
$errorMessage = ';
$sourcePath = Str_replace ("", "-", $sourcePath);
$destinationPath = Str_replace ("", "-", $destinationPath);
if (!ftp_mkdir ($connectionId, $destinationPath))
{
$errorMessage. = "Unable to create directory at". $destinationPath. " (it may already exist) ";
}
Ftp_site ($connectionId, ' CHMOD 0777 '. $destinationPath);
Ftp_chdir ($connectionId, $destinationPath);
Print $sourcePath. ' to '. $destinationPath. " <br/> ";
if (Is_dir ($sourcePath))
{
ChDir ($sourcePath);
$handle =opendir ('. ');
while (($file = Readdir ($handle))!==false)
{
if ($file!= ".") && ($file!= "..."))
{
if (Is_dir ($file))
{
$errorMessage. = Copyfileviaftp ($sourcePath. Directory_separator. $file, $file, $connectionId);
ChDir ($sourcePath);
if (!ftp_cdup ($connectionId))
{
$errorMessage. = "Unable to ftp_cdup";
}
}
Else
{
if (substr ($file, strlen ($file)-4, 4)!= ". zip")
{
$fp = fopen ($file, "R");
if (!ftp_fput ($connectionId, Str_replace ("", "_", $file), $fp, ftp_binary))
{
$errorMessage. = "Unable to Ftp_fput ().";
}
Ftp_site ($connectionId, ' CHMOD 0755 '. Str_replace ("", "_", $file));
}
}
}
}
Closedir ($handle);
}
return $errorMessage;
}