I am trying to connect to secured ftp server in vb.net using FTPClient. I am able to connect and upload/download data through filezilla. But from .net code, I am having timeout issue. Did I make any mistake, or is there anything missing in my following code?
Public Function ftpDownload(ByVal strFileName As String) As FileStream
Try
Dim client As New FtpClient("ftp://xxx.xxx.xxx.xxx")
client.Port = 990
client.Credentials = New NetworkCredential("myusername", "mypassword")
client.EncryptionMode = FtpEncryptionMode.Explicit
client.DataConnectionEncryption = True
client.ReadTimeout = 20000
client.DataConnectionType = FtpDataConnectionType.AutoPassive
'System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
client.Connect()
Dim arr As New MemoryStream()
client.Download(arr, strFileName)
Using responseStream As IO.Stream = arr
Using fs As New IO.FileStream("c:\temp\temp.123", FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
Do
read = responseStream.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
responseStream.Close()
'fs.Flush()
'fs.Close()
Return fs
End Using
responseStream.Close()
End Using
Catch ex As Exception
MsgBox(ex)
Return Nothing
End Try
It is throwing exception from client.Connect(). Following is the screenshot of the exception as seen in quick watch window: