Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

abd1111

Fixed, I think

In case someone sees this - now it seems to be working as intended?
I am not sure what I did the first time. I believe the "$session.add_QueryReceived" Event is doing this in my log file:
Skipping the bad file, and instead of killing the script, it continues on, as initially intended. Correct me if I am wrong?

("/WElness" is a dud file with no extension in this case, not a folder)
. 2026-04-08 08:28:16.768 Starting download of /x/x//Client Folders/x/x/WEllness

> 2026-04-08 08:28:16.769 TYPE I
< 2026-04-08 08:28:16.815 200 Binary mode selected.
> 2026-04-08 08:28:16.815 PASV
< 2026-04-08 08:28:16.859 227 Entering Passive Mode (x)
> 2026-04-08 08:28:16.859 RETR WEllness
. 2026-04-08 08:28:16.859 Connecting to x ...
< 2026-04-08 08:28:16.989 550 Cannot retrieve 'WEllness'.
. 2026-04-08 08:28:16.989 Copying files from remote side failed.
* 2026-04-08 08:28:17.008 (ExtException) **Copying files from remote side failed.**
* 2026-04-08 08:28:17.008 Cannot retrieve 'WEllness'.
. 2026-04-08 08:28:17.008 Asking user:
. 2026-04-08 08:28:17.008 Error transferring file '/x/x/Client Folders/x/x/WEllness'. ("Copying files from remote side failed.","Cannot retrieve 'WEllness'.")
< 2026-04-08 08:28:17.008 Script: Error transferring file '.../Census Files/WEllness'.
< 2026-04-08 08:28:17.009 Script: Copying files from remote side failed.
< 2026-04-08 08:28:17.009 Cannot retrieve 'WEllness'.

. 2026-04-08 08:28:17.045 Answer: Skip

* 2026-04-08 08:28:17.068 (ESkipFile) Error transferring file '.../Census Files/WEllness'.
* 2026-04-08 08:28:17.068 Copying files from remote side failed.
* 2026-04-08 08:28:17.068 Cannot retrieve 'WEllness'.
. 2026-04-08 08:28:17.068 File "(folder path to bad file)" excluded from transfer
* 2026-04-08 08:28:17.077 (ESkipFile)
. 2026-04-08 08:28:17.078 Retrieving directory listing...

> 2026-04-08 08:28:17.078 CWD (moved on to different folder here now)
< 2026-04-08 08:28:17.305 250 (new folder) is the current directory.
abd1111

Re: Corrupt Folder Objects - Script Keeps Stopping on Failure

martin wrote:

The code looks good to me.
Please post complete log. The snippet you have posted does not show what happens after the error.


Oddly enough, that was the end of it, and all log entries mentioning that folder item. The Powershell terminal error showed this:
Exception calling "Check" with "0" argument(s): "Error transferring file '/x/x/Client Folders/x/xCensus Files/WEllness'.

Copying files from remote side failed.
Cannot retrieve 'WEllness'."


Edit:
Why would Win try to download a bad file that does not meet that filemask, anyway? I see in the FTP folder it is called a 'note' file, with no extension (so actually not a corrupt file as I thought before). Shouldn't Win not even recognize that item, anyways? Would adding "*." after the "|" filemask pipe look over those files?
martin

Re: Corrupt Folder Objects - Script Keeps Stopping on Failure

The code looks good to me.
Please post complete log. The snippet you have posted does not show what happens after the error.
abd1111

Corrupt Folder Objects - Script Keeps Stopping on Failure

I did a good read up on the $session.add_QueryReceived, but it is not just clicking with me. My PowerShell script to download a bunch of files hits this one corrupt folder item and kills it. I intend to continue past the corrupt folder objects. Something with the .Check()? I tried adding some stuff, but I'm a little confused. Haven't touched PowerShell in a long time. Attached is the code and relevant log snippet.
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
# Set up session options
 
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Ftp
    HostName = "xx.xx.com"
    UserName = "xxxx"
    Password = $plainPass
    FtpSecure = [WinSCP.FtpSecure]::Implicit
    Timeout = New-TimeSpan -Seconds 600
}
 
# Session object
$session = New-Object WinSCP.Session
 
# Log Path
$session.SessionLogPath = "C:\Users\User1\C1\Documents\ImportExportTeam\Daily_Eligibility_Runs_REPO\Logs\.logs\USHC.log"
 
# Connect
$session.add_QueryReceived({
    $entry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') | SKIPPED | $($_.Message)"
    Add-Content -Path $errorLog -Value $entry
    $_.Continue()
})
 
$session.Open($sessionOptions)
 
# Transfer Options
$transferOptions = New-Object WinSCP.TransferOptions
 
$transferOptions.AddRawSettings("ExcludeEmptyDirectories", "1")
$transferOptions.AddRawSettings("NewerOnly", "1")
 
## Paycheck Comparisons---------------
 
$remotePath = "/1 A CLIENTS/xCompany/Client Folders/"
$localPath = "C:\Users\User1\C1\Eligibility Files\xCompany\"
 
# Masking
$transferOptions.FileMask = "*Paycheck Comparison*/*.* | *Archive*/; *Opt*/; *Enrollment*/; *Census*/; *Deduction*/; *Actual*/"
 
# Download files
$result = $session.GetFiles($remotePath, $localPath, $False, $transferOptions)
$result.Check()
 
foreach ($transfer in $result.Transfers) {
    $entry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') | $($transfer.FileName)"
    Add-Content -Path $downloadLog -Value $entry
}

Log snippet file attached.