sftp 協定
使用SSH協定進行FTP傳輸的協定稱為SFTP(安全檔案傳輸)Sftp和Ftp都是檔案傳輸協定。
差異:
sftp是ssh內含的協定(ssh是加密的telnet協定),只要sshd伺服器啟動了,它就可用,而且sftp安全性較高,它本身不需要ftp伺服器啟動。 sftp = ssh ftp(安全文件傳輸協定)。 (推薦學習:PHP程式設計從入門到精通)
由於ftp是明文傳輸的,沒有安全性,而sftp基於ssh,傳輸內容是加密過的,較為安全。 目前網路不太安全,以前用telnet的都改用ssh2(SSH1已被破解)。
sftp這個工具和ftp用法一樣。但是它的傳輸檔案是透過ssl加密了的,即使被截獲了也無法破解。而且sftp相比ftp功能要多一些,多了一些檔案屬性的設定
// 注意这里只是为了介绍ftp ,并没有做验证 ; class ftp{ // 初始配置为NULL private $config =NULL ; // 连接为NULL private $conn = NULL; public function init($config){ $this->config = $config; } // ftp 连接 public function connect(){ return $this->conn = ftp_connect($this->config['host'],$this->config['port'])); } // 传输数据 传输层协议,获得数据 true or false public function download($remote, $local,$mode = 'auto'){ return $result = @ftp_get($this->conn, $localpath, $remotepath, $mode); } // 传输数据 传输层协议,上传数据 true or false public function upload($remote, $local,$mode = 'auto'){ return $result = @ftp_put($this->conn, $localpath, $remotepath, $mode); } // 删除文件 public function remove($remote){ return $result = @ftp_delete($this->conn_id, $file); } } // 使用 $config = array( 'hostname' => 'localhost', 'username' => 'root', 'password' => 'root', 'port' => 21 ) ; $ftp = new Ftp(); $ftp->connect($config); $ftp->upload('ftp_err.log','ftp_upload.log'); $ftp->download('ftp_upload.log','ftp_download.log'); /*根据上面的三个协议写出基于ssh 的ftp 类 我们知道进行身份认证的方式有两种:公钥;密码 ; (1) 使用密码登陆 (2) 免密码登陆也就是使用公钥登陆 */ class sftp{ // 初始配置为NULL private $config =NULL ; // 连接为NULL private $conn = NULL; // 是否使用秘钥登陆 private $use_pubkey_file= false; // 初始化 public function init($config){ $this->config = $config ; } // 连接ssh ,连接有两种方式(1) 使用密码 // (2) 使用秘钥 public function connect(){ $methods['hostkey'] = $use_pubkey_file ? 'ssh-rsa' : [] ; $con = ssh2_connect($this->config['host'], $this->config['port'], $methods); //(1) 使用秘钥的时候 if($use_pubkey_file){ // 用户认证协议 $rc = ssh2_auth_pubkey_file( $conn, $this->config['user'], $this->config['pubkey_file'], $this->config['privkey_file'], $this->config['passphrase']) ); //(2) 使用登陆用户名字和登陆密码 }else{ $rc = ssh2_auth_password( $conn, $this->conf_['user'],$this->conf_['passwd']); } return $rc ; } // 传输数据 传输层协议,获得数据 public function download($remote, $local){ return ssh2_scp_recv($this->conn_, $remote, $local); } //传输数据 传输层协议,写入ftp服务器数据 public function upload($remote, $local,$file_mode=0664){ return ssh2_scp_send($this->conn_, $local, $remote, $file_mode); } // 删除文件 public function remove($remote){ $sftp = ssh2_sftp($this->conn_); $rc = false; if (is_dir("ssh2.sftp://{$sftp}/{$remote}")) { $rc = false ; // ssh 删除文件夹 $rc = ssh2_sftp_rmdir($sftp, $remote); } else { // 删除文件 $rc = ssh2_sftp_unlink($sftp, $remote); } return $rc; } } $config = [ "host" => "192.168.1.1 ", // ftp地址 "user" => "***", "port" => "22", "pubkey_path" => "/root/.ssh/id_rsa.pub", // 公钥的存储地址 "privkey_path" => "/root/.ssh/id_rsa", // 私钥的存储地址 ]; $handle = new SftpAccess(); $handle->init($config); $rc = $handle->connect(); $handle->getData(remote, $local);
以上是php連接sftp有什麼用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文比較了酸和基本數據庫模型,詳細介紹了它們的特徵和適當的用例。酸優先確定數據完整性和一致性,適合財務和電子商務應用程序,而基礎則側重於可用性和

本文討論了確保PHP文件上傳的確保,以防止諸如代碼注入之類的漏洞。它專注於文件類型驗證,安全存儲和錯誤處理以增強應用程序安全性。

本文討論了在PHP中實施API速率限制的策略,包括諸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之類的庫。它還涵蓋監視,動態調整速率限制和手

本文討論了使用password_hash和pyspasswify在PHP中使用密碼的好處。主要論點是,這些功能通過自動鹽,強大的哈希算法和SECH來增強密碼保護

本文討論了OWASP在PHP和緩解策略中的十大漏洞。關鍵問題包括注射,驗證損壞和XSS,並提供用於監視和保護PHP應用程序的推薦工具。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Dreamweaver CS6
視覺化網頁開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Linux新版
SublimeText3 Linux最新版

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)