-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-reports.ps1
50 lines (47 loc) · 1.49 KB
/
deploy-reports.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Setup env variables
param (
[Parameter(Mandatory=$true)][string]$UserName,
[Parameter(Mandatory=$true)][string]$Password,
[Parameter(Mandatory=$true)][string]$HostIP,
[Parameter(Mandatory=$true)][string]$HostKey,
[Parameter(Mandatory=$true)][string]$ProjectLocation,
[Parameter(Mandatory=$true)][string]$OutputDirectory
)
$CurrentDirectory = Get-Location
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = $HostIP
UserName = $UserName
Password = $Password
SshHostKeyFingerprint = $HostKey
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
Write-Host "Uploading files"
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Remote, "$CurrentDirectory\tasks", "$ProjectLocation", $False)
$synchronizationResult.Check()
Write-Host $synchronizationResult.Uploads
foreach ($uploadedFile in $synchronizationResult.Uploads)
{
if ($uploadedFile.Error -eq $Null)
{
Write-Host "Upload of $($uploadedFile.FileName) succeeded"
}
else
{
Write-Host (
"Upload of $($uploadedFile.FileName) failed: $($uploadedFile.Error.Message)")
}
}
}
finally
{
$session.Dispose()
}