使用pysftp从SFTP服务器将文件下载到本地计算机时出现PermissionError
Getting PermissionError while downloading files to local machine from SFTP server using pysftp
我无法从 SFTP 服务器复制文件。我收到权限错误。
我试过在 os.mkdirs()
函数中更改模式。
sftp = pysftp.Connection(host = myhostname, username= myusername, password= mypassword, port=22, cnopts=mycn`enter code here`opts)
os.makedirs('S:\work\Automation\ML\Procressed data\FY20\FW'+fweek+'\output', exist_ok=True)
localpath = 'S:\work\Automation\ML\Procressed data\FY20\'+fweek+'\output'
englishpath ='dell.ccaprocessrepository/output_ts_2020'+fweek+'_English_EU.txt'
chinapath = 'repository/output_ts_2020'+fweek+'_CHT.txt'
japanpath = 'repository/output_ts_2020'+fweek+'_Japan.txt'
koreapath = 'repository/output_ts_2020'+fweek+'_Korea.txt'
sftp.get(remotepath= englishpath, localpath= localpath)
sftp.get(remotepath= chinapath, localpath= localpath)
sftp.get(remotepath= japanpath, localpath= localpath)
sftp.get(remotepath= koreapath, localpath= localpath)
PermissionError: [Errno 13] Permission denied: 'S:\work\Automation\ML\Procressed data\FY20\29\output'
pysftp Connection.get
method 的 localpath
参数是 文件 的路径,下载的内容应存储到该路径。
您 localpath
中的 output
是 文件夹 ,而不是 文件。
您需要在路径中附加一个文件名。
englishlocalpath = localpath + '\output_ts_2020'+fweek+'_English_EU.txt'
sftp.get(remotepath=englishpath, localpath=englishlocalpath)
或者,将本地工作目录更改为 localpath
,您可以省略 localpath
参数。 pysftp 会将文件下载到工作目录,并保留原始名称(取自 remotepath
参数):
os.chdir(localpath)
sftp.get(remotepath=englishpath)
sftp.get(remotepath=chinapath)
sftp.get(remotepath=japanpath)
sftp.get(remotepath=koreapath)
我无法从 SFTP 服务器复制文件。我收到权限错误。
我试过在 os.mkdirs()
函数中更改模式。
sftp = pysftp.Connection(host = myhostname, username= myusername, password= mypassword, port=22, cnopts=mycn`enter code here`opts)
os.makedirs('S:\work\Automation\ML\Procressed data\FY20\FW'+fweek+'\output', exist_ok=True)
localpath = 'S:\work\Automation\ML\Procressed data\FY20\'+fweek+'\output'
englishpath ='dell.ccaprocessrepository/output_ts_2020'+fweek+'_English_EU.txt'
chinapath = 'repository/output_ts_2020'+fweek+'_CHT.txt'
japanpath = 'repository/output_ts_2020'+fweek+'_Japan.txt'
koreapath = 'repository/output_ts_2020'+fweek+'_Korea.txt'
sftp.get(remotepath= englishpath, localpath= localpath)
sftp.get(remotepath= chinapath, localpath= localpath)
sftp.get(remotepath= japanpath, localpath= localpath)
sftp.get(remotepath= koreapath, localpath= localpath)
PermissionError: [Errno 13] Permission denied: 'S:\work\Automation\ML\Procressed data\FY20\29\output'
pysftp Connection.get
method 的 localpath
参数是 文件 的路径,下载的内容应存储到该路径。
您 localpath
中的 output
是 文件夹 ,而不是 文件。
您需要在路径中附加一个文件名。
englishlocalpath = localpath + '\output_ts_2020'+fweek+'_English_EU.txt'
sftp.get(remotepath=englishpath, localpath=englishlocalpath)
或者,将本地工作目录更改为 localpath
,您可以省略 localpath
参数。 pysftp 会将文件下载到工作目录,并保留原始名称(取自 remotepath
参数):
os.chdir(localpath)
sftp.get(remotepath=englishpath)
sftp.get(remotepath=chinapath)
sftp.get(remotepath=japanpath)
sftp.get(remotepath=koreapath)