Скрипт FTPS Powershell
Мне было интересно, можно ли сделать сценарий FTPS powershell для загрузки и загрузки всех файлов с одинаковым расширением файла? Я посмотрел и всегда вижу ftp-скрипты.
Я использовал этот скрипт.
$sourceuri = ""
$targetpath = ""
$username = ""
$password = ""
$ftprequest = [System.Net.FtpWebRequest]::create($sourceuri)
$ftprequest.Credentials =
New-Object System.Net.NetworkCredential($username,$password)
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$ftprequest.UseBinary = $false
$ftprequest.KeepAlive = $false
$ftprequest.EnableSsl = $true
$ftpresponse = $ftprequest.GetResponse()
$responsestream = $ftpresponse.GetResponseStream()
$targetfile = New-Object IO.FileStream ($targetpath,[IO.FileMode]::Create)
[byte[]]$readbuffer = New-Object byte[] 1024
do{
$readlength = $responsestream.Read($readbuffer,0,1024)
$targetfile.Write($readbuffer,0,$readlength)
}
while ($readlength -ne 0)
$targetfile.close()
Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
At H:\-----.ps1:21 char:1
+ $ftpresponse = $ftprequest.GetResponse()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
You cannot call a method on a null-valued expression.
At H:\-------.ps1:24 char:1
+ $responsestream = $ftpresponse.GetResponseStream()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Вот некоторые из ошибок, которые я получил.