Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
WSAECONNRESET An existing connection was forcibly closed by the remote host.Explains the meaning of the "WSAECONNRESET An existing connection was forcibly closed by the remote host." error and demonstrates a way to reproduce it by setting the "No Transfer Timeout" setting on a FileZilla FTP server to a very small value.
CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @sTmp0 nvarchar(4000) DECLARE @ftp int EXEC @hr = sp_OACreate 'Chilkat.Ftp2', @ftp OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int -- Any string unlocks the component for the 1st 30-days. EXEC sp_OAMethod @ftp, 'UnlockComponent', @success OUT, 'Anything for 30-day trial' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OASetProperty @ftp, 'Hostname', '192.168.1.108' EXEC sp_OASetProperty @ftp, 'Username', 'myLogin' EXEC sp_OASetProperty @ftp, 'Password', 'myPassword' -- Connect and login to the FTP server. EXEC sp_OAMethod @ftp, 'Connect', @success OUT IF @success <> 1 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OASetProperty @ftp, 'Passive', 1 -- In this example, we've set the FileZilla FTP Server's -- "No Transfer Timeout" to 5 seconds. This is a setting -- on the FTP server (not in the Chilkat FTP component). -- It causes the server to disconnect from the client after -- 5 seconds of no upload or download activity. As you'll see, -- sending commands over the control channel, such as -- NOOP (no-operation) commands will have no effect. -- It is an upload, download, or directory listing that is required. -- This code will wait 10 seconds before proceeding with -- the PutFile. This should be enough time for the FileZilla -- server to disconnect. DECLARE @i int SELECT @i = 0 WHILE @i <= 10 BEGIN -- Sleep for 1 second EXEC sp_OAMethod @ftp, 'SleepMs', NULL, 1000 -- Send a NOOP command to the FTP server. -- After about 5 iterations, it should fail and the LastErrorText -- will contain this message: -- WSAECONNRESET An existing connection was forcibly closed by the remote host. EXEC sp_OAMethod @ftp, 'Noop', @success OUT IF @success <> 1 BEGIN EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 BREAK END SELECT @i = @i + 1 END -- What happens if we try to upload a file without an existing -- connection? -- Let's do it and find out... -- Upload a file. DECLARE @localFilename nvarchar(4000) SELECT @localFilename = 'c:/temp/hamlet.xml' DECLARE @remoteFilename nvarchar(4000) SELECT @remoteFilename = 'hamlet.xml' EXEC sp_OAMethod @ftp, 'PutFile', @success OUT, @localFilename, @remoteFilename IF @success <> 1 BEGIN -- In Active mode (i.e. non-passive), we get this error: -- "Failed to get socket's IP address. Socket may already be disconnected." -- In Passive mode, we'll get this error: -- " No socket exists for sending (2)" EXEC sp_OAGetProperty @ftp, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 RETURN END EXEC sp_OAMethod @ftp, 'Disconnect', NULL PRINT 'File Uploaded!' END GO |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.