'Settings required to establish a connection with the server Public Function UploadToServer(ByVal FileName As String) As Boolean Try Dim ftpRequest As FtpWebRequest = CType(FtpWebRequest.Create(New Uri("ftp://" + FileName)), FtpWebRequest) ftpRequest.Method = WebRequestMethods.Ftp.UploadFile ftpRequest.Proxy = Nothing ftpRequest.UseBinary = True ftpRequest.EnableSsl = True ftpRequest.KeepAlive = True ftpRequest.Credentials = New NetworkCredential("test", "test1234") 'Selection of file to be uploaded Dim ff As FileInfo = New FileInfo("D:\Sample2\" + FileName) Dim fileContents() As Byte = New Byte((ff.Length) - 1) {} Dim fr As FileStream = ff.OpenRead fr.Read(fileContents, 0, Convert.ToInt32(ff.Length)) 'Dim no As Integer = ftpRequest.ServicePoint.CurrentConnections 'ftpRequest.ServicePoint.ConnectionLimit = 10 ftpRequest.Timeout = 999999999 ftpRequest.ReadWriteTimeout = 999999999 Dim writer As Stream = ftpRequest.GetRequestStream writer.Write(fileContents, 0, fileContents.Length) ' // Am getting error like The underlying connection war closed. and The remote certificate is invalid according ' //to the validation procedure. writer.Close() fr.Close() 'ftpRequest.Abort() flag = "Y" Return True Catch ex As Exception 'Return False flag = "N" Throw 'Finally End Try End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)