so I've been trying to figure out this script to try and get a daily file uploaded to our FTP server. I've used this script in the past with success since the files are uploaded with a consistent file name: IE: FILE_NAME_2016-05-25.csv (Where the current days date is always formatted like this)
So this works when the file name maintains this consistency, but I need to use it to get a file that has an inconsistent value, appended to the end. IE: FILE_NAME_2016-05-25_0503 (The last value never being consistent).
So is there a way to use a wildcard character at the end of the file/folder variable to account for this?
My code (Note I am very new to powershell)
#Get's file from the FTP using today's date
Write-Host "Please wait while your file downloads"
$server = "ftp.server.net"
$user = "user"
$pass = "pass"
$invocation = (Get-Variable MyInvocation).Value
$localpath = Split-Path $invocation.MyCommand.Path
$TodayDate = (get-date)
$FileNameDate = date $TodayDate -f yyyy-MM-dd
$remotefilepath = "inbox/sub1/sub2/FILE_NAME_$FileNameDate_[*].txt"
$localfilename = "FILE_NAME_$FileNameDate.csv"
$localfilelocation = "$localpath\$localfilename"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user, $pass)
$uri = New-Object System.Uri(“ftp://$server/$remotefilepath”)
$webclient.DownloadFile($uri, $localfilelocation)
I tried to use a wildcard character at the end but it appears I am doing something wrong