Created
January 21, 2019 20:54
-
-
Save spy86/d6831ebc2676f087cb01e3eae64983f3 to your computer and use it in GitHub Desktop.
Script to FTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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