Skip to content

Instantly share code, notes, and snippets.

@zabustak
Forked from harnerdesigns/Upload.ps1
Created April 21, 2020 01:33
Show Gist options
  • Save zabustak/d03972c54242dab4bcecc2ef6455b37a to your computer and use it in GitHub Desktop.
Save zabustak/d03972c54242dab4bcecc2ef6455b37a to your computer and use it in GitHub Desktop.
A PowerShell script to upload via FTP a directory one file at a time. I basically got tired of having to open FileZilla and wait for it to connect and then waiting for everything to upload.
#Directory To Pull Files From
$Dir="C:\foo\bar\toBeUploaded"
#FTP site and credentials
$ftp = "ftp://ftp.somesite.com/"
$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 "*.*")){
"Uploading $item..."
$uri = New-Object System.Uri($ftp+$item.Name)
$webclient.UploadFile($uri, $item.FullName)
#Archive Uploaded Files By Date
$date = (Get-Date).ToString('MM-dd-yyyy')
$path = "C:\foo\bar\uploaded\" + $date
#If Today's folder doesn't exist, make one.
If(!(test-path $path))
{
New-Item -ItemType Directory -Force -Path $path
}
#Move file to today's folder
Move-Item $item.FullName -destination $path
}
#Beep When Finished
function b($a,$b){
[console]::beep($a,$b)
}
b 1000 100;
b 1333 200;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment