我正在使用 PowerShell 脚本通过 FTP 上传文件。我使用的脚本如下:
$File = "C:\test\test01.txt"
$ftp = "ftp://MyUsername:MyPassword@MyHostName/"
"ftp url: $ftp"
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)
"Uploading $File..."
$webclient.UploadFile($uri,$File)
但是当我运行脚本时,出现以下错误:
Exception calling "UploadFile" with "2" argument(s): "The requested URI is invalid for this FTP command."
At C:\FTP.ps1:11 char:1
+ $webclient.UploadFile($uri,$File)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
我使用的 Powershell 版本如下:
Major Minor Build Revision
----- ----- ----- --------
3 0 -1 -1
任何人都知道如何解决这个问题?
谢谢