我想使用powershell脚本在FTP服务器上传图像但我不断收到错误WebClient请求期间发生异常,不确定我的脚本有什么问题。有什么帮助吗?
$FTPHost = "ftp://xxxx/"
$FTPUser = "xxxx"
$FTPPass = "xxxxx"
$source = "C:\Images"
$webClient = New-Object System.Net.WebClient
$webClient.Credentials = New-Object System.Net.NetworkCredential($FTPUser, $FTPPass)
$files = get-childitem $source -recurse -force
foreach ($file in $files)
{
Write-Host "Uploading $file"
$webClient.UploadFile("$FTPHost", $file.Name)
}
$webClient.Dspose()
答案 0 :(得分:0)
尝试以这种方式使用UploadFile
:
$webClient.UploadFile("$FTPHost" + "/" + $file.Name, "STOR", $file.FullName)
您必须为其提供完整的文件名以及存储位置。