Skip to content

Commit

Permalink
misc: update release upload script
Browse files Browse the repository at this point in the history
to be more universal… hopefully.

[no ci] [skip ci]
  • Loading branch information
revam committed Mar 29, 2023
1 parent 292dddf commit 6d6d56e
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/UploadRelease.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
# Parameters/arguments.
Param(
[string]$remote = "Artifact.bin",
[string]$local = "Artifact.bin"
)

# Variables.
$username = $env:FTP_USERNAME;
$password = $env:FTP_PASSWORD;
$ftp_server = $env:FTP_SERVER;
$localPath = (Get-Location).Path + "/" + $local
$remotePath = "ftp://$ftp_server/files/shoko-server/$remote"

$current = [string](Get-Location);
$client = New-Object System.Net.WebClient;
$client.Credentials = New-Object System.Net.NetworkCredential($username, $password);

# Log inputs.
Write-Output "Starting file upload...";
Write-Output "Remote file: $remote";
Write-Output "Local file: $local";
Write-Output "Remote path: /files/shoko-server/$remote";
Write-Output "Local path: $localPath";

try {
$client.UploadFile("ftp://$ftp_server/files/shoko-server/$remote", "$current/$local");
Write-Output "Done!";
# Create the request.
$request = [System.Net.FtpWebRequest]::Create($remotePath);
$request.Method = [System.Net.WebRequestMethods+FTP]::UploadFile;
$request.Credentials = New-Object System.Net.NetworkCredential($username, $password);

# Upload the file.
[byte[]] $bytes = [System.IO.File]::ReadAllBytes($localPath);
[System.IO.Stream]$stream = $request.GetRequestStream();
$stream.Write($bytes, 0, $bytes.Length);
$stream.Close();
$stream.Dispose();

# Wait for an answer…
$response = [System.Net.FtpWebResponse]$request.GetResponse();
$result = $response.StatusDescription;
$response.Close();

# …and report status.
Write-Output $result;
}
catch {
# Write out errors.
Write-Error $_.Exception.Message;
throw;
}

0 comments on commit 6d6d56e

Please sign in to comment.