Presumably the principle traverses all non-excluded files in the project, and then gets文件修改时间晚于文件上一次修改时间 The files then upload these files via FTP to the corresponding directory specific code as follows:Because it's just a tool, the code is messy, forgive me
- Error_reporting (7);
- if ($_server[' server_addr ') exit;//prohibit running under the Web server
- $_get[' Exclude ' = Array (' Number.txt ', ' uploads ', ' Zend ', ' docs ', ' cache ', ' You ', ' managesdk '); Exclude upload directory, defined as global variable
- $fileobj = new Filerfile ();
- $path = "/data/longtu/"; The root directory of the project directory
- $files = $fileobj->zip ($path); Filter out the latest modification files
- $path = Str_replace ("/data/longtu/", "", $path);
- $config = Array (
- ' Hostname ' = ' xxx.xxx.xx.xxx ',//ftp server address
- ' username ' = ' xxx ',//ftp user
- ' Password ' = '? xxxxxxxxxxx ',//ftp password
- ' Port ' = 21//port
- );
- $FTP = new FTP ();
- $ftp->connect ($config);//Linked server
- $a = $ftp->filelist ();
- $LOCAL _root = Realpath (dirname (__dir__). /.. /.. /");
- ChDir ($LOCAL _root);
- foreach ($files as $k = = $v) {
- $f = $path. $v;
- $tmp = $ftp->upload ($f, $f);
- if ($tmp) {
- echo "Upload $f-success \ n";
- }
- }
- $ftp->download (' Ftp_upload.log ', ' ftp_download.log ');
- //
- $ftp->upload (' Ftp_err.log ', ' ftp_upload.log ');
- $ftp->download (' Ftp_upload.log ', ' ftp_download.log ');
- /*
- *
- *
- * $dir = "/test";
- if (@ftp_chdir ($conn, $dir))
- Determine if a folder
- * Enter description here ...
- * @author Administrator
- *
- */
- Class Filerfile
- {
- var $time _path;
- Private $fctimes = Array ();
- function Zip ($dir)
- {
- $this->time_path = RTrim ($dir, "/"). " /.~~~time.php ";
- @unlink ($this->time_path);
- $filelist = $this-Getfilelist ($dir);
- File_put_contents ($this->time_path, " fctimes,true).";
- return $filelist;
- }
- function Appendfilectime ($file)
- {
- $time _file_path = $this->time_path;
- $ftime = @include ($time _file_path);
- $ftime = $ftime? $ftime: Array ();
- $time = Filectime ($file);
- if (!file_exists ($time _file_path)) file_put_contents ($time _file_path, " }
- function Getfilebyfilectime ($file)
- {
- Static $time _data;
- $time _file_path = $this->time_path;
- if (! $time _data) {
- $time _data= @include_once ($time _file_path);
- }
- $time _data = $time _data? $time _data:array ();
- Var_dump ($file, $time _data[$file] = = Filectime ($file));
- echo $file. " \ t ". $time _data[$file]." \ n ";
- if ($time _data[$file] = = Filemtime ($file)) {
- return false;
- }else{
- return $file;
- }
- }
- function Getfilelist ($dir, $path = "")
- {
- Static $TMPP = "";
- if ($path = = "" &&! $tmpp) {
- $TMPP = $dir;
- }
- $d = Dir ($dir);
- $files = Array ();
- if ($d)
- {
- $pathP =str_replace ($tmpp, "", $dir);
- $pathP =str_replace (Array ("\\\\", "/"), Directory_separator, $pathP);
- $pathP =str_replace (directory_separator. Directory_separator,directory_separator, $pathP);
- while ($f = $d->read ())
- {
- if ($f = = '. ' | | $f = = '.. ' | | $f {0}== '. ' | | $f = = ' Zend ' | | in_array ($f, $_get[' Exclude ']) continue;
- $newdir = RTrim ($dir, "/"). " /". $f;
- if (Is_dir ($newdir)) {
- $files = Array_merge ($files, $this->getfilelist ($newdir, $newdir));
- }else{
- $abspath _file = (RTrim ($dir, "/")? RTrim ($dir, "/"). " /":"). $f;
- $this->fctimes[$abspath _file] = filemtime ($abspath _file);
- if (! $this->getfilebyfilectime ($abspath _file)) continue;
- $file = (RTrim ($pathP, "/")? RTrim ($pathP, "/"). " /":"). $f;
- $files [] = $file;
- }
- }
- }
- return $files;
- }
- }
- /**
- * Copy-write CodeIgniter FTP class
- * FTP basic operation:
- * 1) landing; Connect
- * 2) List of current directory files; FileList
- * 3) directory changes; Chgdir
- * 4) rename/move; Rename
- * 5) Create a folder; mkdir
- * 6) Delete; Delete_dir/delete_file
- * 7) Upload; Upload
- * 8) Download Download
- *
- * @author Quanshuidingdang
- */
- Class FTP {
- Private $hostname = ';
- Private $username = ';
- Private $password = ';
- Private $port = 21;
- Private $passive = TRUE;
- Private $debug = TRUE;
- Private $conn _id= FALSE;
- /**
- * Constructor function
- *
- * @param array configuration arrays: $config = array (' hostname ' = = ', ' username ' + ', ' password ' = ' = ', ' port ' = = ' ...);
- */
- Public function __construct ($config = Array ()) {
- if (count ($config) > 0) {
- $this->_init ($config);
- }
- }
- /**
- * FTP connection
- *
- * @access Public
- * @param array Configuration
- * @return Boolean
- */
- Public Function Connect ($config = Array ()) {
- if (count ($config) > 0) {
- $this->_init ($config);
- }
- if (FALSE = = = ($this->conn_id = @ftp_connect ($this->hostname, $this->port)) {
- if ($this->debug = = = TRUE) {
- $this->_error ("Ftp_unable_to_connect");
- }
- return FALSE;
- }
- if (! $this->_login ()) {
- if ($this->debug = = = TRUE) {
- $this->_error ("Ftp_unable_to_login");
- }
- return FALSE;
- }
- if ($this->passive = = = TRUE) {
- FTP_PASV ($this->conn_id, TRUE);
- }
- return TRUE;
- }
- /**
- * folder is present
- * @param unknown_type $path
- */
- Public Function is_dir_exists ($path)
- {
- return $this->chgdir ($path);
- }
- /**
- * Directory Change
- *
- * @access Public
- * @param string directory identifier (FTP)
- * @param boolean
- * @return Boolean
- */
- Public Function Chgdir ($path = ", $supress _DEBUG = FALSE) {
- if ($path = = "OR! $this->_isconn ()) {
- return FALSE;
- }
- $result = @ftp_chdir ($this->conn_id, $path);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE and $supress _debug = = FALSE) {
- $this->_error ("ftp_unable_to_chgdir:dir[". $path. "]");
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Directory Generation
- *
- * @access Public
- * @param string directory identifier (FTP)
- * @param int file permissions List
- * @return Boolean
- */
- Public Function mkdir ($path = ", $permissions = NULL) {
- if ($path = = "OR! $this->_isconn ()) {
- return FALSE;
- }
- $result = @ftp_mkdir ($this->conn_id, $path);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_unable_to_mkdir:dir[". $path. "]");
- }
- return FALSE;
- }
- if (! Is_null ($permissions)) {
- $this->chmod ($path, (int) $permissions);
- }
- return TRUE;
- }
- /**
- * Upload
- *
- * @access Public
- * @param string Local directory identity
- * @param string Remote directory identification (FTP)
- * @param string upload mode auto | | Ascii
- * @param int file permission list after uploading
- * @return Boolean
- */
- Public function upload ($localpath, $remotepath, $mode = ' auto ', $permissions = NULL) {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- if (! file_exists ($localpath)) {
- if ($this->debug = = = TRUE) {
- $this->_error ("Ftp_no_source_file:". $localpath);
- }
- return FALSE;
- }
- if ($mode = = ' auto ') {
- $ext = $this->_getext ($localpath);
- $mode = $this->_settype ($ext);
- }
- $mode = ($mode = = ' ASCII ')? Ftp_ascii:ftp_binary;
- $result = @ftp_put ($this->conn_id, $remotepath, $localpath, $mode);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_unable_to_upload:localpath[". $localpath. "] /remotepath[". $remotepath."] ");
- }
- return FALSE;
- }
- if (! Is_null ($permissions)) {
- $this->chmod ($remotepath, (int) $permissions);
- }
- return TRUE;
- }
- /**
- * Download
- *
- * @access Public
- * @param string Remote directory identification (FTP)
- * @param string Local directory identity
- * @param string download mode Auto | | Ascii
- * @return Boolean
- */
- Public function Download ($remotepath, $localpath, $mode = ' auto ') {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- if ($mode = = ' auto ') {
- $ext = $this->_getext ($remotepath);
- $mode = $this->_settype ($ext);
- }
- $mode = ($mode = = ' ASCII ')? Ftp_ascii:ftp_binary;
- $result = @ftp_get ($this->conn_id, $localpath, $remotepath, $mode);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_unable_to_download:localpath[". $localpath. "] -remotepath[". $remotepath."] ");
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Rename/move
- *
- * @access Public
- * @param string Remote directory identification (FTP)
- * @param string new directory ID
- * @param Boolean to determine whether to rename (FALSE) or move (TRUE)
- * @return Boolean
- */
- Public function Rename ($oldname, $newname, $move = FALSE) {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- $result = @ftp_rename ($this->conn_id, $oldname, $newname);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $msg = ($move = = FALSE)? "Ftp_unable_to_rename": "Ftp_unable_to_move";
- $this->_error ($msg);
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Delete Files
- *
- * @access Public
- * @param string file identifier (FTP)
- * @return Boolean
- */
- Public Function Delete_file ($file) {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- $result = @ftp_delete ($this->conn_id, $file);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_unable_to_delete_file:file[". $file. "]");
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Delete Folder
- *
- * @access Public
- * @param string directory identifier (FTP)
- * @return Boolean
- */
- Public Function Delete_dir ($path) {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- Add backslash ' \ ' to the '/' character of the directory macro
- $path = Preg_replace ("/(. +?) \/*$/"," \\1/", $path);
- Get catalog File List
- $filelist = $this->filelist ($path);
- if ($filelist!== FALSE and Count ($filelist) > 0) {
- foreach ($filelist as $item) {
- If we can't delete it, then it could be a folder
- So we recursively call Delete_dir ()
- if (! @delete_file ($item)) {
- $this->delete_dir ($item);
- }
- }
- }
- Delete folder (empty folder)
- $result = @ftp_rmdir ($this->conn_id, $path);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_unable_to_delete_dir:dir[". $path. "]");
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Modify File permissions
- *
- * @access Public
- * @param string directory identifier (FTP)
- * @return Boolean
- */
- Public function chmod ($path, $perm) {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- A function (FTP) that modifies permissions is defined only in PHP5
- if (! function_exists (' Ftp_chmod ')) {
- if ($this->debug = = = TRUE) {
- $this->_error ("Ftp_unable_to_chmod (function)");
- }
- return FALSE;
- }
- $result = @ftp_chmod ($this->conn_id, $perm, $path);
- if ($result = = = FALSE) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_unable_to_chmod:path[". $path. "] -chmod[". $perm."] ");
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Get directory file list
- *
- * @access Public
- * @param string directory identifier (FTP)
- * @return Array
- */
- Public function filelist ($path = '. ') {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- Return Ftp_nlist ($this->conn_id, $path);
- }
- /**
- * Close FTP
- *
- * @access Public
- * @return Boolean
- */
- Public function Close () {
- if (! $this->_isconn ()) {
- return FALSE;
- }
- Return @ftp_close ($this->conn_id);
- }
- /**
- * FTP member variable initialization
- *
- * @access Private
- * @param array Configuration
- * @return void
- */
- Private Function _init ($config = Array ()) {
- foreach ($config as $key = = $val) {
- if (Isset ($this-$key)) {
- $this $key = $val;
- }
- }
- Special character filtering
- $this->hostname = preg_replace (' |. +?:/ /| ', ', $this->hostname);
- }
- /**
- * FTP Login
- *
- * @access Private
- * @return Boolean
- */
- Private Function _login () {
- Return @ftp_login ($this->conn_id, $this->username, $this->password);
- }
- /**
- * Judge con_id
- *
- * @access Private
- * @return Boolean
- */
- Private Function _isconn () {
- if (! Is_resource ($this->conn_id)) {
- if ($this->debug = = = TRUE) {
- $this->_error ("ftp_no_connection");
- }
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Get the suffix extension from the file name
- *
- * @access Private
- * @param string Directory ID
- * @return String
- */
- Private Function _getext ($filename) {
- if (FALSE = = = Strpos ($filename, '. ')) {
- return ' txt ';
- }
- $extarr = Explode ('. ', $filename);
- Return end ($extarr);
- }
- /**
- * Definition of FTP transfer mode ASCII or binary from suffix extension
- *
- * @access Private
- * @param string suffix extension
- * @return String
- */
- Private Function _settype ($ext) {
- $text _type = Array (
- ' TXT ',
- ' Text ',
- ' PHP ',
- ' Phps ',
- ' PhP4 ',
- ' JS ',
- ' CSS ',
- ' HTM ',
- ' HTML ',
- ' Phtml ',
- ' sHTML ',
- ' Log ',
- ' XML '
- );
- Return (In_array ($ext, $text _type))? ' ASCII ': ' binary ';
- }
- /**
- * ERROR log record
- *
- * @access Prvate
- * @return Boolean
- */
- Private Function _error ($msg) {
- Return @file_put_contents ('/tmp/ftp_err.log ', "date[". Date ("Y-m-d h:i:s"). "] -hostname[". $this->hostname."] -username[". $this->username."] -password[". $this->password."] -msg[". $msg."] \ n ", file_append);
- }
- }
- /*end of File ftp.php*/
- /*location/apache group/htdocs/ftp.php*/
Copy Code
|