bfuchs
asked on
Change script to include only particular files.
Hi Experts,
The script below connects to a FTP site and downloads all newest files to a local folder in my pc.
How can I change this script to include only files either with wording "PAT" or "Sched"?
However if file name contains word "Full" it should not be included.
Thanks in advance.
The script below connects to a FTP site and downloads all newest files to a local folder in my pc.
How can I change this script to include only files either with wording "PAT" or "Sched"?
However if file name contains word "Full" it should not be included.
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "sftp.MySite.com"
UserName = "MyUserName"
Password = "MyPWD"
SshHostKeyFingerprint = "1234567890="
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Transfer files
$remotePath = "H:\FTP\*"
$sourcePath = "/Outbox/*"
$destPath = "H:\FTP\"
$destPathNew = "H:\FTP\Caspio\"
$transferOptions = New-Object WinSCP.TransferOptions
while($True)
{
try
{
$transferResult = $session.GetFiles($sourcePath, $destPath, $False, $transferOptions)
$transferResult.Check()
}
finally
{
foreach ($transfer in $transferResult.Transfers)
{
$session.GetFiles($transfer.FileName, $destPathNew, $False, $transferOptions)
Write-Host "Download of $($transfer.FileName) succeeded"
}
$destPathNew1
}
}
Write-Host "Waiting..."
Start-Sleep -Seconds 5
}
finally
{
$session.Dispose()
}
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Perhaps you can solve this too...
https://www.experts-exchange.com/questions/29112257/How-to-copy-only-new-files-from-FTP-site.html#questionAdd
Thanks,
Ben
Perhaps you can solve this too...
https://www.experts-exchange.com/questions/29112257/How-to-copy-only-new-files-from-FTP-site.html#questionAdd
Thanks,
Ben
You are welcome
ASKER