6

Following issue: Using the power shell script below works for transferring a .war file from Server A to Server B via the tomcat manager ONLY when size of the war file is somewhat below 4MB. Everything above that size fails with

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At C:\Temp\deploy.ps1:25 char:2 + (Invoke-WebRequest -InFile "C:\Temp\fancy.war" -URI "https: ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Code that I run via PowerShell on Server A is:

Set-PSDebug -Trace 1
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object 
TrustAllCertsPolicy
$user = "admin"
$pass = "loveit"

$secpass = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpass)
(Invoke-WebRequest -InFile "C:\Temp\fancy.war" -URI "**https**://host99.some.domain:443/manager/text/deploy?path=/fancy&update=true" -Method PUT -Credential $credential -ContentType 'application/zip' -UseBasicParsing -TimeoutSec 120)

I also played around with the server.xml of the tomcat8 and web.xml of the tomcat manager as mentioned in the post How to deploy a war file in Tomcat 7

As seen, with 50 MB I am on the safe side.

\webapps\manager\WEB-INF\web.xml

<multipart-config>
  <!-- 50MB max -->
  <max-file-size>52428800</max-file-size>
  <max-request-size>52428800</max-request-size>
  <file-size-threshold>0</file-size-threshold>
</multipart-config>

server.xml

<Connector port="443" maxPostSize="67589953" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2" useServerCipherSuitesOrder="true" ciphers="TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" server="Web Server" minSpareThreads="25" allowTrace="true" keystoreFile="cert.pfx" keystorePass="" keystoreType="PKCS12" connectionTimeout="100000000" />

Thanks for your help!

B--rian
  • 5,578
  • 10
  • 38
  • 89
fk08
  • 69
  • 3
  • 1
    When SSL is turned of for the tomcat server, then the transfer works straight irrespective on the file size. – fk08 Aug 30 '17 at 17:53
  • I think your issue relates to a change that has happened in the internals. When from powershell you end up inside .net executing an async function then whatever script block you added into your runspace is not available within the async execution context. Please check this with smaller files, because it should have the same behavior. – Alex Sarafian Aug 23 '18 at 10:31
  • Seeing the same problem, a 10mb file works, 100mb does not. – Joe Zack May 02 '19 at 20:14
  • Try using `$wc = [System.Net.WebClient]::new()`, some $wc parameters maybe like `$wc.Credentials`, then `$wc.UploadFile($addr, $method, $filepath)` – filimonic Aug 21 '20 at 23:28
  • Does the transfer rate times the file size exceed your timeout of 120 seconds (2 minutes)? – carrvo Jan 29 '22 at 19:03

0 Answers0