Skip to content

Instantly share code, notes, and snippets.

@spy86
Created January 21, 2019 20:54
Show Gist options
  • Select an option

  • Save spy86/d6831ebc2676f087cb01e3eae64983f3 to your computer and use it in GitHub Desktop.

Select an option

Save spy86/d6831ebc2676f087cb01e3eae64983f3 to your computer and use it in GitHub Desktop.
Script to FTP
#search latest files
$dir = "C:\Users\Admin\Documents"
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
#we specify the directory where all files that we want to upload
$Dir="C:/Users/Admin/Documents/"+ $latest.name
#ftp server
$ftp = "ftp://ftp.someaddress.com/dir/"
$user = "login"
$pass = "password"
$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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment