Post a reply

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)


Topic review


Re: Files downloaded too fast

Use Session.ListDirectory or Session.EnumerateRemoteFiles methods to retrieve list of files. Find the latest file in the list and if it is too new, wait a bit.
This may help a bit:
Downloading the most recent file.
Nicky Grant

Re: Files downloaded too fast

Hi Martin, Thanks for your reply.

You are right that is't just downloading the files.
I run the PowerShell from startup on the server. And it just keeps running.
When I place a file on the FTP it will be downloaded almost instantly.

Maybe I can set an interval time for downloads but when a file is placed just before download this issue can still happen.

That's why I was looking at a way that the script detects a file and wait for a sec before download. But that might not be possible.
I also asked our customer if they can create the file and fill it with data before they put it on the FTP folder. I think that's the best solution here.

Re: Files downloaded too fast

Sorry, I do not understand. Your question sounds like the code is detecting new files, and when it founds some, it downloads them. But your code is not detecting new files. It just downloads them. So where do you way to put the pause? Or what triggers your code to be executed?
Nicky Grant

Files downloaded too fast

I have a problem with a PowerShell script that is downloading files from FTP folder to a local folder. Our customer is first creating a txt file on the FTP folder and then write the data into it. It's a way how their software works. It's probably only milliseconds before the data is written into the file.
Most of the time the downloaded files are ok but sometimes data is missing and we even got files of 0kb.

I think my PowerShell script is downloading the files too fast in that case.
Is the a way to put in a delay so when a new file is put on the FTP it waits for a sec before downloading the file?

Here is the script that I use:
$sessionOptions.AddRawSettings("FSProtocol", "2")
$session = New-Object WinSCP.Session
    # Connect
    # Transfer files
    $session.GetFiles("DataFolder/Spoolfiles/*", "D:\Spoolfiles\*", $True).Check()
    Write-Output "LOOKING FOR DATA.."