-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzip_and_upload.ps1
25 lines (17 loc) · 1.06 KB
/
zip_and_upload.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function ZipAndUpload([string]$ftpUrl, [string]$ftpUsername, [string]$ftpPassword, [string]$inputDirectory) {
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($ftpUsername,$ftpPassword)
$fileName = [System.IO.Path]::GetDirectoryName($inputDirectory)
$uniqueFormatPart = Get-Date -format yyyyMMddHHmmssfff
$destinationPath = $fileName + "_" + $uniqueFormatPart + ".zip"
$destinationFileName = [System.IO.Path]::GetFileName($destinationPath)
write-host $destinationPath
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
[System.IO.Compression.ZipFile]::CreateFromDirectory($inputDirectory, $destinationPath)
write-host "sucessfully created zip file $destinationFileName" -foreground "green"
$uriPath = "$ftpUrl/$destinationFileName"
write-host "uploading file to $uriPath ..."
$uri = New-Object System.Uri($uriPath)
$webclient.UploadFile($uri,$destinationPath)
write-host "successfully uploaded file" -foreground "green"
}