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) –