The latest and most comprehensive PHPFTP operation class, from EaglePHP framework-PHP source code

Source: Internet
Author: User
Tags ftp connection remote ftp server
The latest and most complete PHPFTP operation class comes from the latest and most complete php ftp operation class of the EaglePHP framework, from the EaglePHP framework

 0) {foreach ($ list as $ k => $ v) {$ path = "{$ directory}/{$ v}"; if (self :: isDir ($ path) self: rmdir ($ path); else self: delete ($ path) ;}} return ftp_rmdir (self: $ resource, $ directory);}/***** continuous acquisition/sending of a file (non-blocking) * in a non-segmented manner. ** @ Return int return the constant FTP_FAILED, FTP_FINISHED, or FTP_MOREDATA */public static function nbContinue () {return ftp_nb_continue (self ::$ resource );} /*** retrieve the file on the FTP server and write it into an open file (non-blocking) ** @ param resource $ handle * @ param string $ remote_file * @ param int $ mode * @ param int $ resumepos * @ return int returns ftp_failed or ftp_finished or ftp_moredata */public static function nbFget ($ handle, $ remote_file, $ mode = FTP_ASCI I, $ resumepos = 0) {return ftp_nb_fget (self ::$ resource, $ handle, $ remote_file, $ mode, $ resumepos );} /***** from the opened file to the file on the FTP server (non-blocking) ** @ param unknown_type $ remote_file * @ param unknown_type $ handle * @ param unknown_type $ mode * @ param unknown_type $ startpos */public static function nbFput ($ remote_file, $ handle, $ mode = FTP_ASCII, $ startpos = 0) {return ftp_nb_fput (self: $ resource, $ remote_file, $ handle, $ m Ode, $ startpos);}/*** get the file from the FTP server and write it to the local file (non-blocking) ** @ param string $ local_file * @ param string $ remote_file * @ param int $ mode * @ param int $ resumepos * @ return int returns FTP_FAILED, FTP_FINISHED or FTP_MOREDATA */public static function nbGet ($ local_file, $ remote_file, $ mode = FTP_ASCII, $ resumepos = 0) {return ftp_nb_get (self: $ resource, $ local_file, $ remote_file, $ mode, $ resumepos);}/***** storage One file to the FTP server (non-blocking) ** @ param string $ remote_file * @ param string $ local_file * @ param int $ mode * @ param int $ startpos * @ return int returns FTP_FAILED, FTP_FINISHED or FTP_MOREDATA */public static function nbPut ($ remote_file, $ local_file, $ mode = FTP_ASCII, $ startpos = 0) {return ftp_nb_put (self: $ resource, $ remote_file, $ local_file, $ mode, $ startpos);}/***** returns the list of objects in the given directory ** @ param string $ directo Ry * @ return array */public static function nlist ($ directory) {return ftp_nlist (self: $ resource, $ directory );} /***** return whether the current FTP passive mode is enabled * When the passive mode is enabled, data transmission is started by the client, rather than by the server. ** @ Param bool $ pasv * @ return bool */public static function pasv ($ pasv) {return ftp_pasv (self ::$ resource, $ pasv );} /***** return the current directory name ** @ return string */public static function pwd () {return ftp_pwd (self: $ resource );} /***** return the detailed LIST of objects in the specified directory *. The ftp list command is executed, return the result as an array ** @ param string $ directory * @ return array */public static function rawlist ($ directory) {return ftp_rawlist (self: $ resource, $ direc Token );} /***** change the file or directory name on the FTP server ** @ param string $ oldname * @ param string $ newname * @ return bool */public static function rename ($ oldname, $ newname) {return ftp_rename (self: $ resource, $ oldname, $ newname );} /***** send the SITE command to the server ** @ param string $ command * @ return bool */public static function site ($ command) {return ftp_site (self :: $ resource, $ command);}/*** returns the size of the specified file ** @ param string $ remot E_file * @ return int if the specified file does not exist or an error occurs,-1 is returned. Some FTP servers may not support this feature. */Public static function size ($ remote_file) {return ftp_size (self ::$ resource, $ remote_file );} /***** open a secure ssl-ftp connection * Note: this function requires the OpenSSL extension library to support ** @ param string $ host * @ param int $ port * @ param int $ timeout * @ return resource */public static function sslConnect ($ host, $ port = 21, $ timeout = 90) {return ftp_ssl_connect ($ host, $ port, $ timeout );} /***** return the operating system type of the remote FTP server. ** @ return string */public static Function compute Ype () {return ftp_cmdype (self: $ resource) ;}/ *** sends a configuration command to the remote FTP server to allocate space for uploaded files. * Note: Many FTP servers do not support this command. ** @ Param int $ filesize: the number of bytes allocated. * @ Param string $ result the response text of the server indicates that a variable is provided by referencing the returned result. * @ Return bool */public static function alloc ($ filesize, & $ result = '') {return ftp_alloc (self ::$ resource, $ filesize, $ result );} /***** determine whether the directory is ** @ param string $ remote_file * @ return bool */public static function isDir ($ remote_file) {return (self :: size ($ remote_file) ===- 1 & self: rawlist ($ remote_file )! = False )? True: false;}/***** obtain the ftp transmission mode based on the file suffix ** @ param string $ file * @ return string */private static function _ getTransferMode ($ file) {$ extArr = array ('txt ', 'text', 'php', 'phps', 'php4 ', 'js', 'css', 'htm ', 'html', 'phpml', 'shtml', 'log', 'xml'); if ($ pos = strrpos ($ file ,'. ') = false) return FTP_ASCII; $ ext = substr ($ file, $ pos + 1); return in_array ($ ext, $ extArr )? FTP_ASCII: FTP_BINARY ;} /***** upload a file to the FTP server ** @ param string $ local_file * @ param string $ remote_file * @ param int $ mode * @ param int $ permissions * @ return void * /public static function upload ($ local_file, $ remote_file, $ mode = null, $ permissions = null) {if (! File_exists ($ local_file) throw_exception ('ftp _ no_source_file: '. $ local_file); $ mode = is_null ($ mode )? Self: _ getTransferMode ($ local_file): $ mode; if (! Self: put ($ remote_file, $ local_file, $ mode) throw_exception ("ftp_unable_to_upload: local_file [{$ local_file}]/remote_file [{$ remote_file}]"); if (! Is_null ($ permissions) self: chmod ($ permissions, $ remote_file); return true;}/*** Upload directory to FTP server * Note: the uploaded directory or file name cannot contain Chinese characters ** @ param string $ local_dir * @ param string $ remote_dir * @ param int $ mode * @ param int $ permissions */public static function uploadDir ($ local_dir, $ remote_dir, $ permissions = null) {$ list = Folder: read ($ local_dir); if (count ($ list)> 0) {if (! Self: isDir ($ remote_dir) self: mkdir ($ remote_dir, $ permissions); foreach ($ list as $ k => $ v) {$ local_path = $ local_dir. '/'. $ v; $ remote_path = $ remote_dir. '/'. $ v; if (Folder: isDir ($ local_path) self: uploadDir ($ local_path, $ remote_path); else self: upload ($ local_path, $ remote_path, null, $ permissions);} return true;} return false;}/***** download an object from ftp to a local device ** @ param string $ remote_file * @ param string $ local_fil E * @ param int $ mode * @ return bool */public static function download ($ remote_file, $ local_file, $ mode = null) {$ mode = is_null ($ mode )? Self: _ getTransferMode ($ remote_file): $ mode; if (! Self: get ($ local_file, $ remote_file, $ mode) throw_exception ("ftp_unable_to_download: local_file [{$ local_file}]-remote_file [{$ remote_file}]"); return true;}/*** download the ftp folder to the local device ** @ param string $ remote_dir * @ param string $ local_dir */public static function downloadDir ($ remote_dir, $ local_dir) {$ list = self: nlist ($ remote_dir); if (count ($ list)> 0) {if (! Folder: isDir ($ local_dir) mk_dir ($ local_dir); foreach ($ list as $ k = >$ v) {$ remote_path = $ remote_dir. '/'. $ v; $ local_path = $ local_dir. '/'. $ v; if (self: isDir ($ remote_path) self: downloadDir ($ remote_path, $ local_path); else self: download ($ remote_path, $ local_path );} return true;} return false;} test code: Ftp: connect ('2017. 168.16.188 ', 'test', '123'); // $ a = Ftp: get ('d:/t.txt', 'php. ini '); // $ a = Date: format ('Y-m-d H: I: S', Ftp: mdtm ('php. ini '); // $ a = Ftp: mkdir ('maojian'); // $ a = Ftp: nlist ('test '); // $ a = Ftp: pwd (); // $ a = Ftp: rawlist ('bak'); // $ a = Ftp :: rename ('000000', 'AAA _ ftp_test '); // $ a = Ftp: mkdir ('/qq/1111/'); // $ a = Ftp :: rmdir ('hahahaha'); // $ a = Ftp: using Ype (); // $ a = Ftp: isDir ('AAA _ ftp_test/tttt /'); // $ a = Ftp: upload ('d:/aaa.txt ', 'aaa.txt'); // $ a = Ftp: delete('aaa.txt '); // $ a = Ftp:: uploadDir ('d:/TDDownload ','/hahaha'); // $ a = Ftp: downloadDir ('/hahaha', 'd:/aaaa '); var_dump ($ );

The above is the latest and most complete php ftp operation class from the EaglePHP framework. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.