-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.ps1.sample
51 lines (39 loc) · 1.32 KB
/
upload.ps1.sample
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
51
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("\\c:\Program Files (x86)\WinSCP\WinSCPnet.dll") | Out-Null
# Session.FileTransferProgress event handler
function FileTransferProgress {
param($e)
# New line for every new file
if (($script:lastFileName -ne $Null) -and
($script:lastFileName -ne $e.FileName)) {
Write-Host
}
# Print transfer progress
Write-Host -NoNewline ("`r{0} ({1:P0})" -f $e.FileName, $e.FileProgress)
# Remember a name of the last file reported
$script:lastFileName = $e.FileName
}
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Scp
HostName = "host"
PortNumber = 2121
UserName = "user"
Password = "password"
SshHostKeyFingerprint = "ssh-ed25519 256 print"
}
$session = New-Object WinSCP.Session
try {
# Will continuously report progress of transfer
$session.add_FileTransferProgress( { FileTransferProgress($_) } )
# Connect
$session.Open($sessionOptions)
$session.ExecuteCommand("pm2 stop x").Check()
# Transfer files
$remotePath = "/remoteDir/TimelapseMP4Webpage/*"
$session.PutFiles("workingDir\publish\*", "/home/timdows/TimelapseMP4Webpage/*").Check()
$session.ExecuteCommand("pm2 start x").Check()
}
finally {
$session.Dispose()
}