Files downloaded too fast

Advertisement

Nicky Grant
Joined:
Posts:
2
Location:
Netherlands

Files downloaded too fast

Hi,
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
 
try
{
    # Connect
    $session.Open($sessionOptions)
 
    # Transfer files
    $session.GetFiles("DataFolder/Spoolfiles/*", "D:\Spoolfiles\*", $True).Check()
    
    Write-Output "LOOKING FOR DATA.."
}
finally
{
    $session.Dispose()
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,506
Location:
Prague, Czechia

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?

Reply with quote

Nicky Grant
Joined:
Posts:
2
Location:
Netherlands

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.

Reply with quote

Advertisement

You can post new topics in this forum