2
我搜索了這個網站,並通過Powershell找到了一個FTPWebRequest示例。我把它使用,它工作正常。但是,當我通過EnableSsl = $ True啓用SSL時,我所得到的只是超時或延遲的「227進入被動模式」,這會打破進程。只要我禁用EnableSsl,我就可以直接通過。有人能指引我朝着正確的方向嗎? FTP主機支持SSL。Powershell FTPWebRequest和EnableSsl = True
我最終想要將方法更改爲DownloadFile並在代碼下載文件後循環查找匹配項。不過,我想安全地做。
# Create an FTPWebRequest object to handle the connection to the FTP server
$ftprequest = [System.Net.FtpWebRequest]::Create($sourceuri)
# Set the request's network credentials for an authenticated connection
$ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password)
# Set FTPWebRequest method to ListDirectory
$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory
$ftprequest.EnableSsl = $True
$ftprequest.UseBinary = $False
$ftprequest.UsePassive = $True
$ftprequest.KeepAlive = $False
$ftpresponse = $ftprequest.GetResponse()
Write-Out $ftpresponse.StatusCode
Write-Out $ftpresponse.StatusDescription