Download file from FTP based on extensions in PowerShell

浪尽此生 提交于 2019-12-08 09:25:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!