Description
Some days ago i had to upload some files to an FTP server. The files were sql server profiler traces and the size of every trace was 300MB aprox. The internet connection wasn''t good at all and it took really long to upload a single file, so i decided to perform the task during the night, but of course i wasn''t willing to stay in front of the computer seeing how the files were uploaded or to upload the files by hand. So i made my own powershell script to solve the problem. The next morning all files were uploaded :).
Script
PowerShell
Edit Script
#we specify the directory where all files that we want to upload
$Dir="C:/Dir"
#ftp server
$ftp = "ftp://ftp.server.com/dir/"
$user = "user"
$pass = "Pass"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
#list every sql server trace file
foreach($item in (dir $Dir "*.trc")){
"Uploading $item..."
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.UploadFile($uri, $item.FullName)
}