【问题标题】:Uploading file using Paramiko in Python seemingly works, but the file cannot be found on the server在 Python 中使用 Paramiko 上传文件看似可行,但在服务器上找不到文件
【发布时间】: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


    【解决方案1】:

    如果 Paramiko 没有抛出任何错误,则表示上传成功。该文件的结束位置可能与您想要的/预期的不同。

    至少对于测试,如果不是永久的,请尝试绝对绝对路径。不要猜测,使用您在 GUI SFTP 客户端中看到的确切路径。


    另一种可能是服务器以某种方式自动处理上传的文件并将其移走。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 2020-02-14
      相关资源
      最近更新 更多