问题
Have used the following link for monitoring an FTP folder and downloading files from it:
https://jhonatantirado.wordpress.com/2013/12/18/download-and-delete-files-from-ftp-using-powershell/
I need to download only .xml
files.
I am very new to PowerShell, anything simple that I am missing?
if ($line -ne ''| $_.extension -eq '.bpxml-2014' -or $_.extension -eq '.xml')
{
}
The $line
has my filename with extension. How do I check if it has the extension?
回答1:
Windows includes a command line FTP client. It can be run with a command script. Use the -s
switch to specify the script file.
A command like mget *.xml
ought to be a good start.
回答2:
Use
if ($line -Like "*.xml" -or $line -Like ".bpxml-2014")
{
...
}
See PowerShell Comparison Operators.
Alternatively see (my) solution using WinSCP .NET assembly used from a PowerShell script:
Listing files matching wildcard
And just download the matching files using the Session.GetFiles.
来源:https://stackoverflow.com/questions/28785132/download-file-from-ftp-based-on-extensions-in-powershell