将文件上传到SFTP Filezilla

时间:2018-11-14 08:55:24

标签: powershell

我想将文件上传到SFTP Filezilla,但出现错误消息,但无法解决问题

$ftp = "Address"
$Username = "username" 
$Password = "password" 
$Localdir = "address\test.docx"

$webclient = New-Object System.Net.WebClient 
$webclient.Credentials = New-Object System.Net.NetworkCredential($UserName, $Password)

foreach ($item in (dir $Localdir "*.docx")) {

"Uploading $item..."
    $uri = New-Object System.Uri($ftp+$item.Name) 
    Write-Output $uri,$item.FullName
    $webclient.UploadFile($uri, $item.FullName)  
}

执行脚本时,出现错误消息:

  

使用“ 2”作为参数调用“ UploadFile”时发生异常:“ WebClient请求期间发生异常。对于字符C:\ Users \ PCA \ Downloads \ powershell \ test4-see.ps1:15: 5 + $ webclient.UploadFile($ ftp,$ item)   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:未指定:(:) [],MethodInvocationException       + FullyQualifiedErrorId:WebException

如何解决此问题? (我在Windows 10上执行此脚本,而Powershell版本为5.1)

0 个答案:

没有答案