【问题标题】:Upload images on FTP Server using Powershell使用 Powershell 在 FTP 服务器上上传图像
【发布时间】:2016-07-28 16:06:27
【问题描述】:

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

【问题讨论】:

  • 您遇到的错误是什么?
  • Check this topic "使用 PowerShell 通过 FTP 上传文件" 一样!

标签: powershell ftp


【解决方案1】:

尝试以这种方式使用UploadFile:

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

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

【讨论】:

  • 我刚刚尝试过,并得到一个新的错误异常调用“UploadFile”,参数为“3”:“远程服务器返回错误:(550)文件不可用(例如,找不到文件,无权访问)。”在 C:\FTPImages.ps1:24 char:5 + $webClient.UploadFile("$uri" + "/" + $file.Name, "STOR", $file.FullName) + ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
  • 彼得你的建议确实奏效了。有一个额外的斜线导致了这个问题。 ....谢谢
猜你喜欢
  • 2018-09-27
  • 1970-01-01
  • 2017-07-26
  • 2019-09-14
  • 1970-01-01
  • 2018-01-17
  • 2011-09-05
  • 2017-06-11
  • 2011-03-12
相关资源
最近更新 更多