我没有使用 PowerShell 的经验,我需要帮助才能从 FTP 服务器下载多个名称相似的图像.我在这个论坛找到了很多,我只设法下载了一张图片.为此,我必须输入文件名.
I am not experienced with PowerShell and I need help to download several images with similar names from an FTP server. I found a lot in this forum, and I only managed to download one picture. For this I had to enter the name of the file.
我想选择一个日期,然后下载该日期的所有图片并将它们保存在本地文件夹中.我还想将下载图像的名称保存在 .txt 文件中
I would like to select a date and then download all the pictures with this date and save them in a local folder. I would also like to save the names of the downloaded images in a .txt file
那么如何根据日期下载图片呢?
So how can I download the pictures based on the date?
字符串20201009是日期,后面的数字是连续的.
The string 20201009 is the date and the numbers after it are sequential.
希望你明白我的意思,因为这是我第一次在论坛上写东西
I hope you understand what I mean, because it is my first time that I write something in the forum
$UserName = "abc"
$Password = "abc"
$RemoteFileName = "DatenTestKam3_schlecht_20201009_085248_00848.jpg"
$LocalFilePath = "C:UsersDesktopPowerShell$RemoteFileName"
$ServerName = "10.196.195.167/22_test"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($UserName, $Password)
$uri = New-Object System.Uri("ftp://$ServerName/$RemoteFileName")
$webclient.DownloadFile($uri, $LocalFilePath)
如果我理解你的问题,你想下载所有名称包含20201009"的文件.字符串,对吧?
If I understand your question correctly, you want to download all files whose name contains "20201009" string, right?
$url = "ftp://ftp.example.com/remote/path/"
$credentials = New-Object System.Net.NetworkCredential("username", "password")
$request = [System.Net.WebRequest]::Create($url)
$request.Credentials = $credentials
$request.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory
$response = $request.GetResponse()
$reader = New-Object IO.StreamReader $response.GetResponseStream()
$listing = $reader.ReadToEnd()
$reader.Close()
$response.Close()
$localpath = "C:UsersDesktopPowerShell"
$date = "20201009"
$files =
($listing -split "`r`n") |
Where-Object {$_ -like "*$date*"}
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = $credentials
foreach ($file in $files)
{
$localfilepath = (Join-Path $localPath $file)
Write-Host ($file + " => " + $localfilepath)
$webclient.DownloadFile(($url + $file), $localfilepath)
}
如果您使用 WinSCP .NET 程序集,那就更简单了:
Add-Type -Path "WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = "ftp.example.com"
UserName = "username"
Password = "password"
}
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
$localpath = "C:UsersDesktopPowerShell"
$date = "20201009"
$session.GetFilesToDirectory("/remote/path", $localpath, "*$date*").Check()
$session.Dispose()
(我是 WinSCP 的作者)
这篇关于从 FTP 服务器下载名称包含特定字符串的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
ASP Core Azure Active Directory 登录使用角色ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登录使用角色)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph 一起使用)
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超