簡體   English   中英

嘗試從 SFTP 下載到本地機器路徑時出現 Python 錯誤 13

[英]Python Error 13 when trying to download off SFTP to local machine path

當我嘗試將 SFTP 下載到本地計算機時,我收到錯誤 13 Access denied。

當我一步一步分解一切時,一切似乎都奏效了。 它成功連接到 SFTP 並列出了目錄,並且本地路徑也正確連接並列出了,但是在 sftp.get(filepath, localpath) 上它給了我訪問被拒絕的錯誤。

如果有人能夠指導我 - 將不勝感激

from os import listdir
import os
from threading import local
import paramiko
paramiko.util.log_to_file("Client_Update.log")

VersionNumber = input("Please enter the version number to download: ")
print("Version Number is " + VersionNumber)

# Create directory for Version
try:
    os.mkdir("C:\\ClientSoftware\\" +VersionNumber)
    print("Directory created successfully!")
except:
    print("Failed to create Directory")

# Open a transport
host,port = "host IP",22
transport = paramiko.Transport((host,port))

# Auth   
try: 
    username,password = "test","test123"
    transport.connect(None,username,password)

# Access SFTP    
    sftp = paramiko.SFTPClient.from_transport(transport)
    print("...Connection Succesful")
    listdir()
except NameError:
    print("....Connection Failed")
except:
    print("An Error Occured - Please contact Admin for further details")

# Download
try :
    filepath = "/WebService/Client Software/Application Files/" + VersionNumber+"/"
    print("Version Found Succesfully!")
    dirlist = sftp.listdir(filepath)
    print ("Dirlist:", dirlist)
    
    try:
       
        localpath = "C:\\ClientSoftware\\" +VersionNumber+"\\motaDataClientSoftware.7z"
        print (localpath)
        print("local directory found succesfully!")
    except:
        print("Local Path not found, please check if localpath C:\ClientSoftware exists")
    try:
        sftp.get(filepath, localpath)
    except:
        print("An Error Occurred with downloading off SFTP")
        print(filepath, localpath)
except:
    print("FilePath Does not exist, Please check if path exists on SFTP and check your version Number exists")
  
# Close
try:
    if sftp: sftp.close()
    if transport: transport.close()
except:
    print("SFTP not open, failed to close")```

從 Paramiko 手冊(插值一點)來看, SFTP.get()僅適用於文件,而不適用於目錄。

但是,您的輸入路徑是目錄,如使用os.listdir(filepath)和行print("local directory found succesfully!")所示。

更改要獲取的實際遠程和本地文件名的路徑,您應該一切順利。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM