
- Python - 網路程式設計
- Python - 網路簡介
- Python - 網路環境
- Python - Internet 協議
- Python - IP 地址
- Python - DNS 查詢
- Python - 路由
- Python - HTTP 請求
- Python - HTTP 響應
- Python - HTTP 標頭
- Python - 自定義 HTTP 請求
- Python - 請求狀態程式碼
- Python - HTTP 身份驗證
- Python - HTTP 資料下載
- Python - 連線重用
- Python - 網路介面
- Python - 套接字程式設計
- Python - HTTP 客戶端
- Python - HTTP 伺服器
- Python - 構建 URL
- Python - Web 表單提交
- Python - 資料庫和 SQL
- Python - Telnet
- Python - 電子郵件訊息
- Python - SMTP
- Python - POP3
- Python - IMAP
- Python - SSH
- Python - FTP
- Python - SFTP
- Python - Web 伺服器
- Python - 上傳資料
- Python - 代理伺服器
- Python - 目錄列表
- Python - 遠端過程呼叫
- Python - RPC JSON 伺服器
- Python - Google 地圖
- Python - RSS 提要
Python - SFTP
SFTP 又稱為 SSH 檔案傳輸協議。它是一種網路協議,透過任何可靠資料流提供檔案訪問、檔案傳輸和檔案管理。該程式透過安全通道執行,例如 SSH 伺服器已對客戶端進行了身份驗證,並且可以在協議中獲取客戶端使用者身份。
pysftp 模組是一個 SFTP 簡單介面。該模組提供高階抽象和基於任務的例程來處理 SFTP 需求。因此,我們使用以下命令將其模組安裝到我們的 python 環境中。
pip install pysftp
示例
在下例中,我們使用 sftp 登入到遠端伺服器,然後在該目錄中獲取和放置一些檔案。
import pysftp with pysftp.Connection('hostname', username='me', password='secret') as sftp: with sftp.cd('/allcode'): # temporarily chdir to allcode sftp.put('/pycode/filename') # upload file to allcode/pycode on remote sftp.get('remote_file') # get a remote file
當我們執行上面的程式碼,我們能夠看到當前目錄中存在的檔案列表,並且可以在該目錄中放置和獲取一些檔案。
廣告