0
我正在使用的供應商將zip文件上傳到FTP。我需要下載任何上傳和處理,根據需要。使用Powershell下載FTP文件夾中的所有文件
使用Powershell,如何從FTP文件夾下載*.*
?
# Config
$Username = "user"
$Password = "password"
$LocalFile = "C:\tools\file.zip"
$RemoteFile = "ftp://myftpserver:22/Folder1/Folder/file.csv"
# Create a FTPWebRequest
$FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)
$FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$FTPRequest.UseBinary = $true
$FTPRequest.KeepAlive = $false
$ftpRequest.EnableSsl = $true
# Send the ftp request
$FTPResponse = $FTPRequest.GetResponse()
# Get a download stream from the server response
$ResponseStream = $FTPResponse.GetResponseStream()
# Create the target file on the local system and the download buffer
$LocalFileFile = New-Object IO.FileStream ($LocalFile,[IO.FileMode]::Create)
[byte[]]$ReadBuffer = New-Object byte[] 1024
# Loop through the download
do {
$ReadLength = $ResponseStream.Read($ReadBuffer,0,1024)
$LocalFileFile.Write($ReadBuffer,0,$ReadLength)
}
while ($ReadLength -ne 0)
有沒有什麼辦法讓$參數】remotefile像ftp://myftpserver:22/Folder1/Folder/*.zip
或ftp://myftpserver:22/Folder1/Folder/*.*
我的道歉,如果有一個職位相同。我看到一些相似的,但不夠接近回答這個問題。
[Powershell FTP下載文件和子文件夾]的可能重複(http://stackoverflow.com/questions/37080506/powershell-ftp-download-files-and-subfolders) –