我有一个FTP服务器,我的操作员通过FTP页面手动更新它,我不确切知道他什么时候这样做。
我想编写一个脚本来确定修改了哪个文件夹,并返回创建或修改的新文件夹的路径。
我应该说他通常在某个路径中创建一个新文件夹或删除它们。
现在通过ftp_nlist
我递归地读取所有文件和文件夹,然后检查数据库中的路径是否是新的,我保存它,或从数据库中删除这一行。
请分享您的想法和代码以获得最佳评价。
您可以通过bash脚本find
检查文件夹和文件的上次修改时间。这是一些PHP示例:
exec('find . -mtime -1 -type d', $output);
// $output: list of folders modified within 24 hours
unset($output);
exec('find . -mtime -1 -type f', $output);
// $output: list of files modified within 24 hours
unset($output);
exec('find . -mtime +0 -type f', $output);
// $output: list of files modified greater than 24 hours
unset($output);
您应该检查这些选项-amin
,-atime
,-cmin
,-ctime
,-mmin
和-mtime
。
-amin n
File was last accessed n minutes ago.
-atime n
File was last accessed n*24 hours ago. When find figures out
how many 24-hour periods ago the file was last accessed, any
fractional part is ignored, so to match -atime +1, a file has
to have been accessed at least two days ago.
-cmin n
File's status was last changed n minutes ago.
-ctime n
File's status was last changed n*24 hours ago. See the
comments for -atime to understand how rounding affects the
interpretation of file status change times.
-mmin n
File's data was last modified n minutes ago.
-mtime n
File's data was last modified n*24 hours ago. See the
comments for -atime to understand how rounding affects the
interpretation of file modification times.