You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Transferetto模块下载SFTP文件时遇RemoteFile参数错误求助

解决Transferetto模块Receive-SFTPFile参数错误问题

你遇到的Receive-SFTPFile : 找不到匹配参数名称“RemoteFile”的参数错误,核心原因是参数名称使用错误,同时对Get-SFTPList返回的对象处理有误,修正方案如下:

错误点说明

  • Transferetto的Receive-SFTPFile cmdlet没有-RemoteFile参数,正确参数名为-RemotePath
  • Get-SFTPList返回的是SFTP文件对象,直接传入会导致路径解析错误,需要取对象的FullName属性作为远程路径

修正后的脚本

Set-ExecutionPolicy RemoteSigned -Scope Process -Force
Import-Module Transferetto

$SftpClient = Connect-SFTP -Server '100.100.00.00' -Username 'FRG_100_22' -Password 'dfggrty'

$List = Get-SFTPList -SftpClient $SftpClient -Path '/FRG'
# 强制删除本地目录所有文件(含隐藏文件)
Get-Childitem -Path "\data\files" -Force | Remove-Item -Force
$downloadedFiles = @()

# 批量下载文件
foreach($originalSFtpFile in $list) {
    # 修正参数名,同时传入远程文件的完整路径
    $downloadedFile = Receive-SFTPFile -SftpClient $SftpClient -RemotePath $originalSFtpFile.FullName -LocalPath "\data\files" -LocalExists Overwrite -VerifyOptions Retry, None
    Write-Host "Downloaded file $($originalSFtpFile.Name) in folder $($downloadedFile.LocalPath)"
    $downloadedFiles += $downloadedFile
}

Disconnect-SFTP -SftpClient $SftpClient

额外说明

  • 原脚本中\data iles是转义字符问题,修正为\data\files确保路径正确
  • 删除文件时添加-Force参数,避免因权限或隐藏文件导致删除失败

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 13:15:56