Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Automating ftp download with powershell

$
0
0

I need to setup a scheduled task that is going to download files from an ftp location (or just run it manually)

I have the following for a ps1

$File = "c:\store\somefilename.zip"
$ftp = "ftp://username:password@example.com/pub/outbound/somefilename.zip""ftp url: $ftp"

$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)

"Downloading $File..."

$webclient.DownloadFile($uri, $File)

I'm guessing I can set $File to *.* but I don't want to download the same files everytime. I am hoping the users will be moving the files once downloaded but who can quarentee that. What for loop can I add to achieve this?

I found the following but not sure how I would alter my original to add this in.

foreach($listOut in $listIn)
	{
		$a = ((Get-Date) - [datetime]::ParseExact($listOut.ModifiedDate, "MMM dd HH:mm", $null)).days
     if ($a -le 0)
	{
	Get-FTPItem -path $dirBank\$($listOut.Name) -LocalPath d:\backup\test\$($listOut.Name)
	}
	}

Thanks in advance for the help.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>