删除旧的远程FTP文件夹 [英] Remove Old Remote FTP Folders

查看:121
本文介绍了删除旧的远程FTP文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个MySQL数据库备份脚本,该脚本将备份文件存储在远程FTP服务器中.它会在根目录中创建一个以数据库名称命名的文件夹,然后在每个文件夹中创建一个以当前日期命名的文件夹(格式:yyyy-mm-dd),并在这些文件夹中上传以确切时间命名的备份文件.

我还需要删除旧的二级文件夹(按日期命名);我的意思是文件夹早于4天.这是我遇到的问题.我用ftp_nlist尝试了一些代码,我可以用它列出文件夹,我也可以ftp_mdtm来获取创建日期并将其与到期日期进行比较.但是结果并不顺利.这是我的代码:

...

$skip = array('.', '..', '.ftpquota', '.htaccess');
$expire_date = date('Y-m-d', strtotime('-4 days', time()));

$ff_list = ftp_nlist($con, $db_dir);
foreach($ff_list as $item)
{
    if(in_array($item, $skip))
    {
        continue;
    }
    $mod_time = ftp_mdtm($con, $item);
    if(strtotime($expire_date ) >= $mod_time)
    {
        ftp_rmdir($con, $item);
    }
}

...

请参加,我需要删除所有包含所有内容的旧文件夹,因此我需要合适的删除命令(我不知道ftp_rmdir是否正常工作).

解决方案

尝试一下:

if(strtotime($expire_date ) >= strtotime($mod_time))

I've written a MySQL database backup script which store backup files in remote FTP server. It creates some folders in root named by database name, then in each of them it creates some folders named by current date (Format: yyyy-mm-dd), and it these folders it uploads the backup files named by exact time.

I also need to remove old second level folders (which are named by date); I mean the folders older than 4 days. This is the part I've problem with. I tried some codes with ftp_nlist and I could list folders with it, I also ftp_mdtm to get the creation date and compare it with expiration date. But the result was not okay. Here is my code:

...

$skip = array('.', '..', '.ftpquota', '.htaccess');
$expire_date = date('Y-m-d', strtotime('-4 days', time()));

$ff_list = ftp_nlist($con, $db_dir);
foreach($ff_list as $item)
{
    if(in_array($item, $skip))
    {
        continue;
    }
    $mod_time = ftp_mdtm($con, $item);
    if(strtotime($expire_date ) >= $mod_time)
    {
        ftp_rmdir($con, $item);
    }
}

...

Please attend I need to remove the old folders with all of their contents, So I need the suitable remove command (I don't know if ftp_rmdir works properly).

解决方案

Try this :

if(strtotime($expire_date ) >= strtotime($mod_time))

这篇关于删除旧的远程FTP文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆