php ftp類

來源:互聯網
上載者:User
ftp_server = server; $this->ftp_user = username; $this->ftp_pass = password; $this->ftp_port = port; // 建立串連 $this->conn_id = ftp_connect($this->ftp_server, $this->ftp_port) or die("不能夠串連到 $this->ftp_server"); // 嘗試登陸 if (!ftp_login($this->conn_id, $this->ftp_user, $this->ftp_pass)) { $this->message("串連失敗 $this->ftp_user"); } else { $this->message("串連成功 $this->ftp_user "); } } //功能:建立新的目錄 //$path預設為空白目錄 //建立成功返回true,否則返回false。 function newdir($path = null) { if($this->ftp_is_dir($this->conn_id,$path)||@ftp_mkdir($this->conn_id,$path)) return true; if(!$this->newdir(dirname($path))) return false; ftp_mkdir($this->conn_id,$path); return true; } //驗證是否為目錄 //對$path進行驗證:如果是目錄返回true,否則返回false。 function ftp_is_dir($path) { $original_directory = ftp_pwd($this->conn_id); if(@ftp_chdir($this->conn_id,$path)) { ftp_chdir($this->conn_id,$original_directory); return true; } else return false; } //功能:上傳檔案 //$ftppath:存在ftp伺服器位置;$localpath:本地檔案位置; //上傳成功返回true,否則返回false。 function uploadfile($ftppath = null, $localpath = null) { if(!empty($ftppath) && !empty($localpath)) { $ret = ftp_nb_put($this->conn_id, $ftppath, $localpath, FTP_BINARY); while ($ret == FTP_MOREDATA) { $ret = ftp_nb_continue ($this->conn_id); } if ($ret != FTP_FINISHED) { $this->message( "上傳失敗"); return false; } else { $this->message("上傳成功"); return true; } } } //功能:刪除目錄 //$dir:要刪除的目錄 //刪除成功返回true,否則返回false。 function deldir($dir = null) { if (ftp_rmdir($this->conn_id, $dir)) { $this->message("刪除目錄成功"); return true; } else { $this->message("刪除目錄失敗"); return false; } } //功能:返回目錄 //返回目前的目錄名稱 function redir() { return ftp_pwd($this->conn_id); } //功能:刪除檔案 //$path:檔案路徑 //刪除成功返回true,否則返回false。 function delfile($path = null) { if(ftp_delete($this->conn_id, $path)) { $this->message("刪除檔案成功"); return true; } else { $this->message("刪除檔案失敗"); return false; } } //功能:列印資訊 //$str:要列印的資訊 function message($str = null) { if(!empty($str)) { echo $str; } } //功能:關閉ftp串連 function closeftp() { ftp_close($this->conn_id); } } /* 一下為示範; redir(); $ftppath='/test'; $locpath="/home/liye/public_html/php_ftp/test"; //$conn->uploadfile($ftppath,$locpath); //$conn->newdir('test/123/1233'); //$conn->deldir('test/123/1233'); //$conn->delfile($ftppath); $conn->delfile('ftp.php'); ?> */
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.