Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Wait for download to complete, then copy the file to a new location

$
0
0

I am downloading some files with PowerShell using webclient.downloadfileasync. 

Im using "Start-sleep -s 10" to prevent the files to be copied before it is completed, but sometimes the download takes longer than 10 Seconds or the url is not accessible. Is there some way to check when the file is completed?

Or maybe another solution is to check the url before it even starts downloading.

try 
{
        foreach ($urls in $ip)
    {
    $url = $http + $ip
    $path = $local + $nr + $jpg
    $client = New-Object System.Net.WebClient
    $client.DownloadFileAsync($url, $path)
    }
}
finally 
{ 
    $client.dispose()
}


Start-sleep -s 10
Copy-Item C:\data\*.jpg C:\data\images
$cn.Close()


Viewing all articles
Browse latest Browse all 21975

Trending Articles