Skip to content

Instantly share code, notes, and snippets.

@bpatra
Created December 5, 2020 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpatra/714da12b9c88fc4871d7237d05b51464 to your computer and use it in GitHub Desktop.
Save bpatra/714da12b9c88fc4871d7237d05b51464 to your computer and use it in GitHub Desktop.
$hostName = $env:FtpHostName
$repoDir = $env:RepoDir
$userName = $env:FtpUserName
$pwd = $env:FtpUserPwd
$sitePath = Join-Path $repoDir -ChildPath "_site"
$windscpPath = Join-Path $repoDir -ChildPath "ignored\build\WinSCP"
$dllPath = Join-Path $windscpPath -ChildPath "WinSCPnet.dll"
$exePath = Join-Path $windscpPath -ChildPath "WinSCP.exe"
if(!(Test-Path $dllPath)){
Write-Error "No dll path found! " $dllPath
}
if(!(Test-Path $exePath)){
Write-Error "No exe path found! " $exePath
}
Add-Type -Path $dllPath
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Ftp
$sessionOptions.HostName = $hostName
$sessionOptions.UserName = $userName
$sessionOptions.Password = $pwd
$sessionOptions.FtpSecure = [WinSCP.FtpSecure]::Explicit
$session = New-Object WinSCP.Session
$session.ExecutablePath = $exePath
$session.SessionLogPath = $logpath
try
{
$session.Open($sessionOptions)
Write-Host "Start syncing..."
$transferResult = $session.SynchronizeDirectories([WinSCP.SynchronizationMode]::Remote, $sitePath, "/site/wwwroot", $True, $False,[WinSCP.SynchronizationCriteria]::Size)
$transferResult.Check()
foreach ($transfer in $transferResult.Downloads)
{
Write-Host ("Download of {0} succeeded" -f $transfer.FileName)
}
foreach ($transfer in $transferResult.Uploads)
{
Write-Host ("Upload of {0} succeeded" -f $transfer.FileName)
}
foreach ($transfer in $transferResult.Removals)
{
Write-Host ("Removal of {0} succeeded" -f $transfer.FileName)
}
Write-Host "... finish syncing."
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment