426 Connection closed; transfer aborted.

Problem:
An FTP transfer fails with the following message found in LastErrorText:

426 Connection closed; transfer aborted

Solution:
A local firewall may be blocking the connection. Try switching between Active and Passive mode and try again.

See these examples:

ASP: Active and Passive Modes in FTP
SQL Server: Active and Passive Modes in FTP
C#: Active and Passive Modes in FTP
C++: Active and Passive Modes in FTP
MFC: Active and Passive Modes in FTP
C: Active and Passive Modes in FTP
Delphi: Active and Passive Modes in FTP
Visual FoxPro: Active and Passive Modes in FTP
Java: Active and Passive Modes in FTP
Perl: Active and Passive Modes in FTP
PHP: Active and Passive Modes in FTP
Python: Active and Passive Modes in FTP
Ruby: Active and Passive Modes in FTP
VB.NET: Active and Passive Modes in FTP
Visual Basic: Active and Passive Modes in FTP
VBScript: Active and Passive Modes in FTP

Could not load file or assembly ‘ChilkatDotNet4.dll’ or one of its dependencies.

(Thank you Josh for your helpful information!)

“I see that occasionally information from clients (with the client’s permission) end up on the blog and thought that perhaps this one would qualify. If there is mention of the C++ Runtime, I didn’t find it.

At any rate, I was having trouble getting the ChilkatDotNet4.dll to load. After a conversation with Matt, I tried installing the Microsoft Visual C++ 2010 Redistributable Package – this resolved my issue:

x86 Microsoft Visual C++ 2010 Redistributable Package
x64 Microsoft Visual C++ 2010 Redistributable Package

I’ve included the error messages below to illustrate that the .dll appears to be being found when registered to the GAC (and certainly when placed directly in the web site’s bin), but cannot load its dependencies.

When loaded into GAC but not found (or when in bin):

Could not load file or assembly ‘ChilkatDotNet4.dll’ or one of its dependencies. The specified module could not be found.

When not loaded into GAC and not in bin:

Could not load file or assembly ‘ChilkatDotNet4, Version=9.0.8.0, Culture=neutral, PublicKeyToken=eb5fc1fc52ef09bd’ or one of its dependencies. The system cannot find the file specified.”

IMAP “Not in the authenticated state” Error

The blog post explains the “Not in the authenticated state” error.

ChilkatLog:
SelectMailbox:
DllDate: Feb 15 2010
UnlockPrefix: Anything for 30-day trial
Username: NETWORK SERVICE
Component: .NET 2.0
mailbox: Inbox
Not in the authenticated state

This error happens if the caller is either not connected to an IMAP server, or is connected but the Login method was never called or did not complete successfully. It can happen for one of the following reasons:

  1. A previous IMAP method call failed because of a lost connection; perhaps the application did not check the return status for success failure. (It is important to check the return status of all method calls involving Internet communications.)
  2. The Connect and/or Login methods were never called.
  3. The return values of the Connect and/or Login methods were not checked for success/failure and a failure was not noticed.

SSH / SFTP – Too much time between connect and authentication

The Solution:

Issue solved.   The problem was, that we stepped through the code and because of that too much time elapsed between connect and authentication.  As we ran the program without breakpoints it worked.

The Problem:

The AuthenticatePw method failed and the LastErrorText contained this information:

ChilkatLog:
   AuthenticatePw:
     DllDate: Jan 31 2010
     UnlockPrefix: ***
     Username: ***
     Component: .NET 2.0
     SshVersion: SSH-2.0-XFB.Gateway Windows
     SftpVersion: 0
     login: ***
     sendMessage:
       msgName: SERVICE_REQUEST
       unpaddedLength: 22
       remainder: 6
       paddingLen: 10
       totalSize: 32
     SentServiceReq: ssh-userauth
     numBytesRequested: 16
     Connection closed by server.
     Failed to read data on SSH connection.
     Failed to read packet from SSH server.
     Error reading service accept.
     Socket connection lost.
     Failed.

SSL/TLS Error – SEC_E_INTERNAL_ERROR

Problem:
An SSL/TLS connection failed and the LastErrorText contains “SEC_E_INTERNAL_ERROR”, such as in the error text below:

(See cause solution below)

ChilkatLog:
  Connect:
    DllDate: Dec  4 2009
    UnlockPrefix: ****
    Username: ****
    Component: .NET 2.0
    objectId: 1
    hostname: *.*.*.*
    port: 443
    ssl: 1
    maxWaitMs: 20000
    windowsAccount: ****
    ClientCertDN: ****
    protocol: default
    An existing connection was forcibly closed by the remote host.
    Failed to receive on the TCP socket
    connectionClosed: 0
    timedOut: 0
    Error reading data from server in handshake loop
    Setting scRet = SEC_E_INTERNAL_ERROR
    Error performing handshake
    Failed.

Cause #1:
This is caused when the server-side expect an SSL 3.0 initial packet and cannot handle an SSL 2.0 initial packet. Normally, when a client and server connect and begin the SSL/TLS handshake, the SSL 2.0 packet is the first one sent. It allows the client and server to negotiate and agree upon protocols starting from SSL 2.0 and up (SSL 2.0, SSL 3.0, TLS 1.0, etc.) Normally, the most secure protocol is used and SSL 2.0 is never actually used (unless there is some very very old legacy server that only supports SSL 2.0).

In some cases, the server does not expect the 1st packet to be SSL 2.0 formatted. One such case is the following OpenSSL command:

OpenSSL> s_server -accept 443 -Verify 5 -ssl3 -cert c:\certs\server.pem


Solution #1:

Set the SslProtocol property equal to the string “SSL 3.0”. For example:

socket.SslProtocol = "SSL 3.0";

This applies to all components capable of using SSL/TLS connections: FTP2, HTTP, Socket, IMAP, MailMan, etc.

Cause #2
The server requires the client to provide a certificate for authentication, but none was provided.

Solution #2
Load a Chilkat certificate object with the appropriate client-side certificate (there are many ways of doing this..) and then set the clients-side certificate by calling the SetSslClientCert method. This method exists on all Chilkat objects that use SSL/TLS connections (FTP2, HTTP, Socket, IMAP, MailMan, etc.)

Important: It’s entirely possible that your application might need to apply both solutions.

SFTP File not Found

Question:

I’m trying to open a file on the SFTP server, but I get a “File not Found” error?
Here is the LastErrorText:

ChilkatLog:
 OpenFile:
   DllDate: Dec  2 2009
   UnlockPrefix: Anything for 30-day trial
   Username: IUSR_ABC***
   Component: ActiveX
   SshVersion: SSH-2.0-1.36 sshlib: GlobalScape
   SftpVersion: 3
   hcCurDate: Tue, 08 Dec 2009 13:48:25 +0000
   hcExpire: 1/2010
   filename: test.txt
   access: writeOnly
   createDisposition: createTruncate
   v3Flags: 0x1a
   Sent FXP_OPEN
   StatusResponse:
     Request: FXP_OPEN
     StatusCode: 2
     StatusMessage: File not found
   SshLog: SFTP> Sending SSH_FXP_OPEN
TRAN> CHANNEL_DATA
TRAN* NumBytes: 45
TRAN< CHANNEL_DATA
SFTP< Received SSH_FXP_STATUS

   Failed.


Answer:

You passed “test.txt” to OpenFile, which means you’re trying to open that file in the HOME directory of the SSH/SFTP user account. To solve the problem, you should either pass the full absolute filepath of the file you wish to open, or a relative filepath from the HOME directory of the SSH user account.

SFTP Permission Denied trying to open existing file.


Question:

Why did I get a permission denied error from the server when trying to open an existing file on the SSH/SFTP server? Here’s the LastErrorText:

ChilkatLog:
   DownloadFileByName:
     DllDate: Dec  2 2009
     UnlockPrefix: ***
     Username: Administrator
     Component: ActiveX
     SshVersion: SSH-2.0-CoreFTP-0.1.2
     SftpVersion: 3
     PreserveDate: 0
     fromFilePath: /test.dat.gz
     toFilePath: c:\abc\test.dat.gz
     OpenRemoteFile:
       filename: /test.dat.gz
       access: readOnly
       createDisposition: openExisting
       v3Flags: 0x1
       Sent FXP_OPEN
       StatusResponse:
         Request: FXP_OPEN
         StatusCode: 3
         StatusMessage: Permission denied
       SshLog: 
 SFTP> Sending SSH_FXP_OPEN
 TRAN> CHANNEL_DATA
 TRAN* NumBytes: 59
 TRAN< CHANNEL_DATA
 SFTP< Received SSH_FXP_STATUS

       timeToOpenMs: Elapsed time: 31 millisec
     totalTimeMs: Elapsed time: 31 millisec
     Failed.

Answer:

You are trying to download “/test.dat.gz” from the SSH/SFTP server. Some servers interpret the leading “/” as the root directory of the SSH user account. However, some servers interpret it as the root directory of the default drive (i.e. default filesystem). Your SSH/SFTP server is doing the latter. Your SSH/SFTP user account apparently does not have permission to read the root directory of the default filesystem, and therefore you get a “permission denied”. The solution is to download “./test.dat.gz” to clearly indicate that test.dat.gz is located in the HOME directory of the SSH/SFTP user account.

VB6 – “TYPE MISMATCH (ERROR CODE 13)” or “Invalid Use of New Keyword”

This error occurs if you incorrectly add the ActiveX component to your VB6 project.  Follow these rules:

1) If the ActiveX objects are dynamically created (they are not dragged and dropped onto a form from the palette), then add a Reference to the ActiveX.  You should NOT see the icons for the ActiveX in the palette.  Instances of the ActiveX objects are created by New statements in your code.

2) If the Chilkat ActiveX objects are dragged and dropped onto your form, then add the component via the “Project–>Components” menu, NOT the “Project–>References” menu.  In my opinion, it is always better to create instances of the objects dynamically because the Chilkat objects are not visual controls and won’t be visible on your form anyway at runtime.

3) Never do both — you should either add a Reference (Project–>References) or add the component to the palette (Project–>Components) but NEVER BOTH.

InitializeSftp – Received FAILURE response to subsystem request.

If the SSH server is setup/configured to not allow SFTP, or your SSH user account is not allowed to use SFTP, the InitializeSftp method will return a failed status. Here is an example:

ChilkatLog:
   InitializeSftp:
     DllDate: Oct 30 2009
     UnlockPrefix: ABC123
     Username: chilkat
     Component: .NET 2.0
     SshVersion: SSH-2.0-OpenSSH_4.5
     SftpVersion: 0
     channelType: session
     clientChannel: 200
     initialWindowSize: 327680
     maxPacketSize: 32768
     Sent open channel request
     ClientChannelNum: 200
     ServerChannelNum: 0
     ServerInitialWindowSize: 0
     ServerMaxPacketSize: 32768
     Session channel successfully opened.
     ChannelNum: 200
     ServerChannelNum: 0
     Sent subsystem request
     Received FAILURE response to subsystem request.
     SSH read failed...
     Failed.