Skip to content

Instantly share code, notes, and snippets.

@EinPinsel
Created February 8, 2017 19:12
Show Gist options
  • Save EinPinsel/979806273a0a5df2562d34af857fd3ac to your computer and use it in GitHub Desktop.
Save EinPinsel/979806273a0a5df2562d34af857fd3ac to your computer and use it in GitHub Desktop.
Upload-Factorio-Mods to a SFTP Server from Windows
# Save Factorio-Mod-Pack and probably upload it to a http server via sftp
# Assume "normal" installation
$SftpServer = 'server.blah.com'
$UserName = 'username'
$KeyFile = '$env:userprofile\key.pem' # Make sure the keyfile has no password, because posh-ssh is not ready yet
$SftpPath = '/var/www/mods.server.blah.com'
$FilePath = "$env:appdata\factorio\_mods.zip"
# Create an empty Credential-Object because reasons. (to be honest: posh-ssh is not ready yet)
$nopasswd = New-Object System.Security.SecureString
$Crendtial = New-Object System.Management.Automation.PSCredential ($UserName, $nopasswd)
Set-Location "$env:APPDATA\factorio"
# delete mod.zip
Get-Item _mods.zip -ErrorAction SilentlyContinue | Remove-Item -Force
# repack mod.zip
Compress-Archive -Path .\mods -DestinationPath .\_mods.zip -CompressionLevel NoCompression
# Get Connection to http server using posh-ssh
# Establish the SFTP connection
New-SFTPSession -ComputerName $SftpServer -KeyFile $KeyFile -Credential $Crendtial -Verbose -AcceptKey
# Upload the file to the SFTP path
Set-SFTPFile -SessionId 0 -LocalFile $FilePath -RemotePath $SftpPath -Overwrite
# Disconnect SFTP session
(Get-SFTPSession -SessionId 0).Disconnect()
Get-SFTPSession | Remove-SFTPSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment