![](/img/trans.png)
[英]Using Python, how to download multiple files from a subdirectory on FTP server into a desired directory on local machine?
[英]How to move multiple files from local machine to a sever using Python
我們有一個框架用於驗證少數測試用例,結果將存儲在包含多個文本和圖像的本地機器中。
需要將這些文件從我們的本地主機移動到服務器。
我有服務器IP地址、用戶名和密碼。
所以使用 Python 我需要移動這些文件或將其復制到服務器
如果您要使用ssh
,則必須使用scp
並且有一個專用的 Python 包: Paramiko
。 請參閱 stackoverflow 上的這篇文章。
import paramiko
def createSSHClient(server, port, user, password):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(server, port, user, password)
return client
ssh = createSSHClient(server, port, user, password)
scp = SCPClient(ssh.get_transport())
scp.put([file1,file2],remotePath)
當然,您必須根據名稱指定各種變量。 scp.put
函數將本地文件列表和遠程系統上的目標路徑作為參數。
這不是真正的 Python 問題:您說您有服務器的用戶名和密碼,但這並沒有告訴我們您可以通過哪種方式訪問該服務器。 你有 SSH 訪問權限嗎? 然后將scp
用作命令行程序或使之成為可能的眾多 Python 模塊之一。
這同樣適用於ftp
、 webdav
、 cifs
/ smb
、 nfs
等協議......這一切都取決於您在服務器上訪問/修改/創建文件的方式。 因此,對於你這個極其不准確的問題,我只能給你這個答案。
使用SCP進行傳輸 ssh -i ~/.ssh/id_rsa intel@10.223.98.165 "mkdir < Folder created >"
scp -i ~/.ssh/id_rsa <源>*.txt <目標> 使用 os.system() 感謝您的幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.