chilkat

Chilkat Upload BeginUpdate fails with "Failed to read TLS record (2)" when using Ssl = true


My hoster updated something about my server, I guess the php version, and since then, my php upload script no longer works with Chilkat.Upload.

    Dim _Chil As New Chilkat.Upload
    _Chil.Ssl = True

    _Chil.Hostname = "www.example.com"
    _Chil.Path = "/upload.php"
    _Chil.AddFileReference("file", "D:\test.txt")

    Dim bUploadStarted As Boolean = _Chil.BeginUpload()

    If Not bUploadStarted Then
        MessageBox.Show("Error trying to BeginUpload: " & _Chil.LastErrorText)
        Return
    End If

    Do While _Chil.UploadInProgress
        _Chil.SleepMs(200)
    Loop

    Dim bSuccess As Boolean = _Chil.UploadSuccess
    If Not bSuccess Then
        MessageBox.Show("Error uploading:" & _Chil.LastErrorText)
    Else
        MessageBox.Show("Upload succeeeded. :-)") 
    End If

With .Ssl = true , BeginUpload fails. This is the last error text:

ChilkatLog:
  BeginUpload:
    DllDate: Aug 28 2021
    ChilkatVersion: 9.5.0.88
    UnlockPrefix: NONE
    Architecture: Little Endian; 32-bit
    Language: .NET 4.6 / x86 / VS2015
    VerboseLogging: 0
    usingTls: 1
    Connecting directly to HTTP server
    domain: www.example.com
    port: 80
    socket2Connect:
      connect2:
        connectImplicitSsl:
          clientHandshake:
            clientHandshake2:
              readHandshakeMessages:
                Failed to read TLS record (2)
                tlsRec_msg: 0
                msgLen: 20527
                nReadNBytes: 0
                status: 0
              --readHandshakeMessages
            --clientHandshake2
          --clientHandshake
          Client handshake failed. (3)
        --connectImplicitSsl
        connectFailReason: 103
        Failed to read the TLS server hello.  Retry without TLS 1.3
        connectImplicitSsl:
          clientHandshake:
            clientHandshake2:
              readHandshakeMessages:
                Failed to read TLS record (2)
                tlsRec_msg: 0
                msgLen: 20527
                nReadNBytes: 0
                status: 0
              --readHandshakeMessages
            --clientHandshake2
          --clientHandshake
          Client handshake failed. (3)
        --connectImplicitSsl
        ConnectFailReason: 103
      --connect2
    --socket2Connect
  --BeginUpload
--ChilkatLog

If I remove .Ssl = true, then BeginUpload succeeds, but UploadSuccess return false. The last error text then is:

ChilkatLog:
  BeginUpload:
    DllDate: Aug 28 2021
    ChilkatVersion: 9.5.0.88
    UnlockPrefix: NONE
    Architecture: Little Endian; 32-bit
    Language: .NET 4.6 / x86 / VS2015
    VerboseLogging: 0
    usingTls: 0
    Connecting directly to HTTP server
    domain: www.example.com
    port: 80
  --BeginUpload

If I run the script via the browser, it works fine.

Here is my code:

myform.php:

<center>
    <form action="upload.php" method="post" enctype="multipart/form-data">
   <input type="file" name="file" >
   <input type="submit" name="upload" value="upload file">
 </form>
</center>

upload.php:

<?php
    move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]);
?>

Solution

  • HTTPS uses port 443.

    So using

    _Chil.Port = 443
    

    fixes the problem.