【发布时间】:2021-04-17 13:55:48
【问题描述】:
我是 Python 新手,很抱歉我的英语不好。 我正在尝试将文件“toto.txt”从我的硬盘“d:”保存到我的 Synology NAS。 所以我将为此使用 paramiko,这是代码:
import paramiko
import os
ip_address = "my nas ip"
username = "my username"
password = "mypass"
utilisateur = os.getenv("USERNAME") // to get Windows username
remote_path = f"{utilisateur}/test.txt" // the file downloaded
local_path = "d:/toto.txt" //the file stored on my pc
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip_address,username=username,password=password)
print("Connexion OK >", ip_address)
stdin, stdout, stderr = ssh_client.exec_command(f'mkdir {utilisateur}') //creating folder for the
user
sftp = ssh_client.open_sftp()
sftp.put(local_path,remote_path) // trying to send the file
sftp.close()
ssh_client.close()
我没有收到错误,但什么也没发生。 该文件夹已成功创建,但没有文件正在发送。 有人有想法吗? 非常感谢
【问题讨论】:
标签: python file ssh sftp paramiko