Chilkat has prepared very nice set of components for developers, for various platforms. These components are very handy from time to time.

Recently, I was trying to use Chilkat’s FTP component for a project, I got caught in a problem. My attempt to connect to an FTP server keeps failing with “WSAEWOULDBLOCK”. Chilkat component was kind enough to also give me an error documentation URL, which suggested me that either FTP server is unreachable OR some firewall is blocking connection. I verified all possible reasons but those were not the case.

The strange thing was, I was able to connect to other FTP servers but not this one. Upon spending some more time, I found the reason.

By default, Chilkat FTP component uses EPSV (Extended Passive) if Passive mode is enabled. But some FTP servers, which requires passive mode, can’t do well with Extended Passive mode. So I had to disable this Extended Passive mode to get this going. To do so in Chilkat FTP component, use following property.

ftpObj.UseEpsv = False

Happy Coding!

I just encountered situation where I had to request a page with SSL error.

By default, HttpWebRequest won’t process any request if SSL is invalid but you can override this setting with just one line of code to ignore all SSL error (basically trust all SSL without checking, could be unsafe too).

VB.net

ServicePointManager.ServerCertificateValidationCallback = (Function(sender, certificate, chain, sslPolicyErrors) True)

C#

ServicePointManager.ServerCertificateValidationCallback =((sender, certificate, chain,
sslPolicyErrors) => true); 

I had hard time to find how to convert plain string HTML source to HtmlDocument (.net object).

As HtmlDocument does not have “new” constructor so we can’t create HtmlDocument object on the fly.

I have created following function for this purpose. Hope it helps!!

VB.net

Public Function Html2Doc(ByVal src As String) As HtmlDocument
        Dim w As WebBrowser = New WebBrowser
        w.DocumentText = src
        Do
            Application.DoEvents()
        Loop While w.ReadyState <> WebBrowserReadyState.Complete
        Return w.Document
    End Function

C#

public HtmlDocument Html2Doc(string src)
{
	WebBrowser w = new WebBrowser();
	w.DocumentText = src;
	do
	{
		Application.DoEvents();
	} while (w.ReadyState != WebBrowserReadyState.Complete);
	return w.Document;
}