【问题标题】:FileNotFoundError: When pushing excel files to sftp serverFileNotFoundError:将 excel 文件推送到 sftp 服务器时
【发布时间】:2019-10-04 12:04:26
【问题描述】:

我一直在尝试通过python从windows本地系统将excel文件推送到sftp服务器。

下面是我试过的代码。

import pandas as pd
import paramiko
sftpURL   =  '100.35.1.16'
sftpUser  =  'xyz'
sftpPass  =  'user@123'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy())
ssh.connect(sftpURL, username=sftpUser, password=sftpPass,port=6381)
ftp = ssh.open_sftp()
localPath = "D:/folder/myfolder/abc.xlsx"
sftpPath = "/home/var/reports/abc.xlsx"
files = ftp.put(sftpPath,localPath)

执行此操作后,我看到下面列出了此错误

FileNotFoundError: [WinError 3] The system cannot find the path specified: '/home/var/reports/abc.xlsx'

我能够通过 Filezilla 连接到 sftp 服务器,当我通过 Python 代码列出目录时它也是成功的,但是当通过 Python 将文件推送到同一位置时,我遇到了这个问题。

我也尝试了大部分在线研究,也使用了包 pysftp,但没有运气。

我不确定我哪里出错了。请提出建议。

【问题讨论】:

    标签: python python-3.x file-not-found


    【解决方案1】:

    put() method 的签名是:

    put(localpath, remotepath, callback=None, confirm=True)
    

    看来你已经推翻了你的论点。将您的 put 调用更改为:

    files = ftp.put(localPath, sftpPath)
    

    【讨论】:

    • 嗨 glibdud,我已经尝试过你的建议,这是我得到的错误:OSError: File not open for writing,
    • 这是一个不同的问题。我建议提出一个新问题,并包括该错误的完整追溯。
    • 谢谢,这有效....我在 ftp.put 中使用了完整的文件位置,而不是将其作为变量传递....
    猜你喜欢
    • 2023-01-27
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2022-11-10
    相关资源
    最近更新 更多