Thank you for your help.
- abd1111
*/Analyzer Census/*.* | ZZArchive/; *PaycheckData*/; *PayTemplates*/; *Schedules*/; *GroupInfo*/
Here is a log file I was able to create. The filemask is somewhat similar. Both masks have the same result (timeout error)
*/Analyzer Census/*.* | ZZArchive/
is possibly incorrect. But you didn't tell us what you are trying to achieve. Are you trying to download only Analyzer Census
folders, ignoring all others? The way you specify your file mask, you force WinSCP to walk though ALL the folders on your server to find those subfolders. That seems to take unbearably long. You need to give WinSCP more hints as to what folders to skip. Hard to help more, unless you tell us more about the directory structure.
Are you saying instead of having 3 different blocks of code that connect to the same FTP for different files to retrieve, group those 3 blocks under one$session.Open($sessionOptions)
, and before the$session.Dispose()
?
Are you opening a new connection for each transfer? You better reuse it.
$session.Open($sessionOptions)
, and before the $session.Dispose()
?
Please post logs for your file mask problems.
*Census Data Files/
, Census Data Files/*/*.xlsx
, Census Data Files/*
, NamedCensusFileData.xlsx
, etc.) and they often time out or endlessly run with no output into the local folder.
$session.Timeout = New-TimeSpan -Seconds 600
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = "x"
UserName = "x"
Password = "x"
FtpSecure = [WinSCP.FtpSecure]::Implicit
}
$session = New-Object WinSCP.Session
$remotePath = "/FTPFolder1/Subfolder1/Subf2/"
$localPath = "C:\Users\ABBBB\xxxxxx\xxxxxxx\xxxxxxx\xxxxxx\xxxxxxxx\"
try
{
# Connect
$session.Open($sessionOptions)
$session.Timeout = New-TimeSpan -Seconds 600
# Masking
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "Census Data Files/*/*.xlsx"
# Download files
$transferOptions.AddRawSettings("ExcludeEmptyDirectories", "1")
$session.GetFiles($remotePath, $localPath, $False, $transferOptions).Check()
}
finally
{
# Disconnect, clean up
$session.Dispose()
}