# Force-overwrite WenChuanyi.Api.dll via app_offline (dll size identical -> size-check skipped it) $ErrorActionPreference = "Continue" $h="116.198.221.125"; $p=21; $u="wenchuanyi"; $pw="r7P^f*v7rFts" $LocalDll="D:\CodeBuddy\Pros\WenChuanyi\backend\WenChuanyi.Api\bin\Release\net8.0\publish\WenChuanyi.Api.dll" $Log="D:\CodeBuddy\Pros\WenChuanyi\deploy\force_dll.log" Set-Content $Log "=== force dll start $(Get-Date -Format 'HH:mm:ss') ===" -Encoding UTF8 function L([string]$m){ Add-Content $Log $m -Encoding UTF8; Write-Host $m } function NewR([string]$path,[string]$m,[int]$t=90000){ $r=[System.Net.FtpWebRequest]::Create("ftp://${h}:${p}/"+$path.TrimStart('/')); $r.Method=$m; $r.Credentials=New-Object System.Net.NetworkCredential($u,$pw); $r.UsePassive=$true; $r.UseBinary=$true; $r.KeepAlive=$false; $r.Timeout=$t; return $r } function UpRaw([string]$lp,[string]$rp){ $b=[IO.File]::ReadAllBytes($lp); $r=NewR $rp ([System.Net.WebRequestMethods+Ftp]::UploadFile) 300000 $r.ContentLength=$b.Length; $s=$r.GetRequestStream(); try{ $s.Write($b,0,$b.Length) } finally { $s.Close() } $resp=$r.GetResponse(); try{ $resp.Close() }catch{}; L "UP $rp len=$($b.Length)" } # 1. stop app Set-Content "$env:TEMP\app_offline.htm" "maintenance" -Encoding UTF8 try{ UpRaw "$env:TEMP\app_offline.htm" "/wwwroot/app_offline.htm" }catch{ L "offline up err: $($_.Exception.Message)" } L "wait 7s..."; Start-Sleep -Seconds 7 # 2. force dll try{ UpRaw $LocalDll "/wwwroot/WenChuanyi.Api.dll"; L "DLL FORCE-UP OK" }catch{ L "DLL FAIL: $($_.Exception.Message)" } Start-Sleep -Seconds 1 # 3. remove app_offline -> restart try{ $r=NewR "/wwwroot/app_offline.htm" ([System.Net.WebRequestMethods+Ftp]::DeleteFile); $resp=$r.GetResponse(); try{$resp.Close()}catch{}; L "app_offline removed (restarting)" }catch{ L "offline del err: $($_.Exception.Message)" } Remove-Item "$env:TEMP\app_offline.htm" -ErrorAction SilentlyContinue L "=== force dll end ==="