FTP operation class (copy, move, delete file creation directory) class class_ftp{public $off; return operation status (failed successfully) public $conn
- /**
- * Role: FTP operation class (copy, move, delete files/create directory)
- * QQ Exchange Group: 136112330
- */
- Class Class_ftp
- {
- Public $off; Return operation status (Success/failure)
- public $conn _id; FTP connection
- /**
- * Method: FTP connection
- * @FTP_HOST--FTP host
- * @FTP_PORT--Port
- * @FTP_USER-User name
- * @FTP_PASS--Password
- */
- function __construct ($FTP _host, $FTP _port, $FTP _user, $FTP _pass)
- {
- $this->conn_id = @ftp_connect ($FTP _host, $FTP _port) or Die ("FTP Server Connection failed");
- @ftp_login ($this->conn_id, $FTP _user, $FTP _pass) or Die ("FTP server login failed");
- @ftp_pasv ($this->conn_id,1); Turn on passive simulation
- }
- /**
- * Method: Upload File
- * @path--Local path
- * @newpath--Upload path
- * @type-New If the target directory does not exist
- */
- function Up_file ($path, $newpath, $type =true)
- {
- if ($type) $this->dir_mkdirs ($newpath);
- $this->off = @ftp_put ($this->conn_id, $newpath, $path, ftp_binary);
- if (! $this->off) echo "File upload failed, please check the permissions and path is correct!" ";
- }
- /**
- * Method: Move File
- * @path-The original path
- * @newpath-New Path
- * @type-New If the target directory does not exist
- */
- function Move_file ($path, $newpath, $type =true)
- {
- if ($type) $this->dir_mkdirs ($newpath);
- $this->off = @ftp_rename ($this->conn_id, $path, $newpath);
- if (! $this->off) echo "File move failed, please check the permissions and the original path is correct!" ";
- }
- /**
- * Method: Copy File
- * Description: Due to FTP no copy command, this workaround is: Download and upload to the new path
- * @path-The original path
- * @newpath-New Path
- * @type-New If the target directory does not exist
- */
- function Copy_file ($path, $newpath, $type =true)
- {
- $downpath = "C:/tmp.dat";
- $this->off = @ftp_get ($this->conn_id, $downpath, $path, ftp_binary);//download
- if (! $this->off) echo "File copy failed, please check the permissions and the original path is correct!" ";
- $this->up_file ($downpath, $newpath, $type);
- }
- /**
- * Method: Delete File
- * @path--Path
- */
- function Del_file ($path)
- {
- $this->off = @ftp_delete ($this->conn_id, $path);
- if (! $this->off) echo "File deletion failed, please check the permissions and path is correct!" ";
- }
- /**
- * Method: Generate Directory
- * @path--Path
- */
- function Dir_mkdirs ($path)
- {
- $path _arr = explode ('/', $path); Fetch directory Array
- $file _name = Array_pop ($path _arr); Popup file name
- $path _div = count ($path _arr); Number of layers to be taken
- foreach ($path _arr as $val)//Create Directory
- {
- if (@ftp_chdir ($this->conn_id, $val) = = FALSE)
- {
- $tmp = @ftp_mkdir ($this->conn_id, $val);
- if ($tmp = = FALSE)
- {
- echo "Directory Creation failed, please check the permissions and path is correct!" ";
- Exit
- }
- @ftp_chdir ($this->conn_id, $val);
- }
- }
- for ($i =1; $i = $path _div; $i + +)//fallback to root
- {
- @ftp_cdup ($this->conn_id);
- }
- }
- /**
- * Method: Close FTP connection
- */
- function Close ()
- {
- @ftp_close ($this->conn_id);
- }
- }//class Class_ftp End
- /************************************** Test ***********************************
- $ftp = new Class_ftp (' 192.168.100.143 ', +, ' user ', ' pwd '); Open FTP Connection
- $ftp->up_file (' aa.txt ', ' a/b/c/cc.txt '); Uploading files
- $ftp->move_file (' a/b/c/cc.txt ', ' a/cc.txt '); Moving files
- $ftp->copy_file (' a/cc.txt ', ' a/b/dd.txt '); Copying files
- $ftp->del_file (' a/b/dd.txt '); deleting files
- $ftp->close (); Close FTP connection
- ******************************************************************************/
- ?>
Copy Code Curl Detailed curl_close-closing a Curl session curl_copy_handle-Copy all the contents and parameters of a Curl connection resource curl_errno-returns a numeric number that contains the current session error information curl_error-returns a string containing the current session error message Curl_exec-performing a Curl session Curl_getinfo-gets the information for a Curl connection resource handle curl_init-initialization of a curl session curl_multi_add_handle-Add a separate curl handle resource to a Curl batch session curl_multi_close-close a batch handle resource curl_multi_exec- Resolves a curl batch handle curl_multi_getcontent-returns the text stream of the obtained output curl_multi_info_read-gets the associated transport information for the currently resolved Curl Curl_multi_ init-Initializes a curl batch handle resource Curl_multi_remove_handle-removes a handle resource from the Curl batch handle resource Curl_multi_select-get all the sockets a Ssociated with the curl extension, which can then be "selected" curl_setopt_array-set session parameters as an array for a CURL Curl_setop T-set session parameters for a Curl curl_version-get Curl-related version information The function of the Curl_init () Initializes a curl session, and the Curl_init () function is the only parameter that is optional, Represents a URL address. The function of the Curl_exec () function is to perform a curl session, and the only argument is the handle returned by the Curl_init () function. The function of the Curl_close () function is to close a curl session, and the only argument is the handle returned by the Curl_init () function.
- $url = ' http://www.@@@@@@.com/';
- Initialize Curl
- $curl = Curl_init ($url);
- Curl Timeout 30s
- curl_setopt ($curl, Curlopt_timeout, ' 30 ');
- User-agent Head
- curl_setopt ($curl, Curlopt_useragent, "mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) gecko/20120722 firefox/14.0.1 ");
- Return file stream
- curl_setopt ($curl, Curlopt_returntransfer, TRUE);
- Open header file data stream output
- curl_setopt ($curl, Curlopt_header, 1);
- $string = curl_exec ($curl);
- Var_dump ($string);
- Preg_match_all ('/set-cookie:\stest= (. *)/I ', $string, $results);
- Var_dump ($results);
- ?>
Copy Code
|