Skip to content

Instantly share code, notes, and snippets.

@harnerdesigns
Last active May 20, 2020 16:22
Show Gist options
  • Save harnerdesigns/3fcc7e58d922347cc8fa169326305db2 to your computer and use it in GitHub Desktop.
Save harnerdesigns/3fcc7e58d922347cc8fa169326305db2 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;
@harnerdesigns
Copy link
Author

I have to batch resize and upload a lot of image files. I created an Action in Photoshop that does all the processing (resizing, save as web) and then saves it in a \images\fixed\ folder. After I'm done with a batch of images I run this upload script and it takes everything out of the \images\fixed\ folder, uploads it to the ftp destination, and then moves it to \images\uploaded[date] folder.

It took the processing time for each batch of photos and cut it way down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment