PHP 之ftp客戶端類封裝實現

2022-06-08 14:45:12 字數 3728 閱讀 5812

<?php/**

* class ftpclient */

class

ftpclient

/*** 初始化資料

* @param array $config 配置檔案陣列

*/public

function initialize(array

$config =)

/*** 連線及登入ftp

* @param array $config 配置檔案陣列

* @return bool

*/public

function connect(array

$config =)

if (!$this->_login())

return

true

; }

/*** 上傳檔案到ftp伺服器

* @param string $local_file 本地檔案路徑

* @param string $remote_file 伺服器檔案位址

* @param string $mode 上傳模式(ascii和binary其中之一)

* @param null $permissions 資料夾許可權

* @return bool

*/public

function upload($local_file = '', $remote_file = '', $mode = 'auto', $permissions = null

)

if ($mode == 'auto')

//建立資料夾

$this->_create_remote_dir($remote_file

);

$mode = ($mode == 'ascii') ? ftp_ascii :ftp_binary;

$result = @ftp_put($this->conn, $remote_file, $local_file, $mode);//

同步上傳

if ($result === false

)

return

true

; }

/*** @param string $local_file 本地檔案位址

* @param string $remote_file 遠端檔案位址

* @param string $mode 上傳模式(ascii和binary其中之一)

* @return bool

*/public

function download($local_file = '', $remote_file = '', $mode = 'auto')

$mode = ($mode == 'ascii') ? ftp_ascii :ftp_binary;

$result = @ftp_get($this->conn, $local_file, $remote_file, $mode

);

if ($result === false

)

return

true

; }

/*** 刪除ftp伺服器端檔案

* @param string $remote_file 檔案位址

* @return bool

*/public

function delete_file($remote_file = '')

return

true

; }

/*** ftp建立多級目錄

* @param string $remote_file 要上傳的遠端位址

* @param null $permissions 修改目錄許可權

*/private

function _create_remote_dir($remote_file = '', $permissions = null

)

if ($permissions !== null

) @

ftp_chdir($this->conn, $val

); }

}for ($i = 0; $i

< $path_div; $i++) //

回退到根,因為上面的目錄切換導致當前目錄不在根目錄

}/**

* 遞迴刪除ftp端目錄

* @param string $remote_dir ftp目錄位址

* @return bool

*/public

function delete_dir($remote_dir = '')

else}}

if (@ftp_rmdir($this->conn, $remote_dir) === false

)

return

true

; }

/*** 更改 ftp 伺服器上的檔案或目錄名

* @param string $old_file 舊檔案/資料夾名

* @param string $new_file 新檔案/資料夾名

* @return bool

*/public

function remane($old_file = '', $new_file = '')

return

true

; }

/***

* @param string $remote_path

*//*

* * 列出ftp指定目錄

* @param string $remote_path 伺服器上的路徑

* @return array

*/public

function list_file($remote_path = '')

/*** 獲取檔案的字尾名

* @param string $local_file 本地檔案

* @return bool|string

*/private

function _get_ext($local_file = '')

/*** 根據檔案字尾獲取上傳編碼

* @param string $ext

* @return string

*/private

function _set_type($ext = '')

/*** 修改目錄許可權

* @param $path 目錄路徑

* @param int $mode 許可權值

* @return bool

*/private

function _chmod($path, $mode = 0755)

return

true

; }

/*** 登入ftp伺服器

* @return bool

*/private

function

_login()

/*** 獲取上傳錯誤資訊

* @return string

*/public

function

get_error_msg()

/*** 關閉ftp連線

* @return bool

*/public

function

close()

}

FTP客戶端程式

ftp客戶端程式,vc6.0下除錯通過 client.c include client.h define sol socket 0xffff int fill host addr char host ip addr,struct sockaddr in host,int port else retu...

ftp客戶端程式

include include include include include pragma comment lib,ws2 32.lib file fp socket client,upload wsadata wsadata int wsareturn int portnum char spor...

android tcp客戶端 封裝

我感覺,簡單的tcp通訊網上應該容易搜到,但對tcp加密,以及tcp當做http通訊和接收推送時,就會有衝突吧。最後我封裝了它 這是tcp 部分 created by zhu on 2017 11 16.public classmyserviceextendsservice override pub...