首页 文章

使用Powershell在FTP服务器上上传图像

提问于
浏览
-1

我想使用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()

1 回答

  • 0

    尝试以这种方式使用 UploadFile

    $webClient.UploadFile("$FTPHost" + "/" + $file.Name, "STOR", $file.FullName)
    

    您必须为其提供完整的文件名以及存储位置 .

相关问题