ftpphp_PHP: FTP 函数 - Manual

//If you want to move or replicate the folder hierarchy from your current server to another remote server. Then this will be helpful as this will browse the current server's directory and at the same time it will copy that file in the remote server in the same directory.

//This script will copy all the files from this directory and subdirectory to another remote server via FTP

function rec_copy ($source_path, $destination_path, $con)

{

ftp_mkdir($con, $destination_path);

ftp_site($con, 'CHMOD 0777 '.$destination_path);

ftp_chdir($con,$destination_path);

if (is_dir($source_path))

{

chdir($source_path);

$handle=opendir('.');

while (($file = readdir($handle))!==false)

{

if (($file != ".") && ($file != ".."))

{

if (is_dir($file))

{

// here i am restricting the folder name 'propertyimages' from being copied to remote server. -- VK

if($file != "propertyimages")

{

rec_copy ($source_path."/".$file, $file, $con);

chdir($source_path);

ftp_cdup($con);

}

}

if (is_file($file))

{

$fp = fopen($file,"r");

// this will convert spaces to '_' so that it will not throw error.  -- VK

ftp_fput ($con, str_replace(" ", "_", $file), $fp,FTP_BINARY);

ftp_site($con, 'CHMOD 0755 '.str_replace(" ", "_", $file));

}

}

}

closedir($handle);

}

}

// make a FTP connection --VK

$con = ftp_connect("69.18.213.131",21);

$login_result = ftp_login($con,"username","password");

// this is the root path for the remote server-- VK

$rootpath = "mainwebsite_html";

// this is the physical path of the source directory. actually u can also use the relative path. -- VK

$sourcepath = realpath("../")."/resdesk";

// this directory name will only change the top most directory and not the inner one -- VK

$destination_dir_name = "resdesk_".$account_id."/";

rec_copy ($sourcepath, $destination_dir_name, $con);

if (function_exists("ftp_close"))

{

ftp_close($con);

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值