Tag Archives: ftp

Simple powershell automated FTP upload script

[This post was originally posted on my personal blog, http://simplystallings.com]

At work, we manually patch our web servers. Part of the process requires ftping the updates to each server. This process is tedious considering the number of web servers and number of steps required. I decided this past patch Tuesday that I would invest a little time into automating the process using powershell.

I located a simple ftp upload script located @ http://poshcode.org/1134. With a few modifications I had my script:

$file = "somefilename"
$filePath = "C:\" + $file
for ($i=0;$i-lt$servers.length;$i++)
{
"ftp url: $ftp"
#FTP URL syntax
$ftp = $servers[$i]+$file
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftp)
"Uploading $File..."
$webclient.UploadFile($uri, $filePath)
}

I added an array that contains the ftp URL syntax for each web server then I iterate over the array using a for loop. Continue reading Simple powershell automated FTP upload script