This page has moved. You will be automatically redirected to its new location in 10 seconds. If you aren't forwarded to the new page, click here.

Search This Blog

Wednesday, June 10, 2009

.NET Framework and FTPS

I have been trying for many days to set up a connection with an FTPS server but was not able to connect and retrieve even just a list of files. I wanted to achieve it by simply using the FTPWebRequest already available in .NET framework.

I tried the following link and many others:

http://blogs.msdn.com/adarshk/archive/2005/04/22/410925.aspx


After an effort of 2-3 days, however, I came to know that the .NET framework 2.0 till now supports only EXPLICIT FTP over SSL and not Implicit connection (which is usually established above port 990)


http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/491341d3-0dd6-4c60-94c9-ca4d4cf3450a/


http://www.developmentnow.com/g/46_2006_5_0_0_755554/implicit-ftp--SSL-problem.htm


Turned out I could not do this without an external component involved. I tested the component available here and was able to connect to my FTP and didnt even require to verify the client certificate:


http://www.rebex.net/download/GetFileNotify.aspx?f=RebexTotalPack-Trial-1.0.3428.0-DotNet2.0.exe


A sample code of the function I used is:


Public Function GetFileByRebex()

Dim ftp As New Ftp()

ftp.Connect(ConfigurationManager.AppSettings("FTPUrl").ToString(), 990, Nothing, FtpSecurity.Implicit)

ftp.Login(ConfigurationManager.AppSettings("FTPUser"), ConfigurationManager.AppSettings("FTPPw"))

ftp.ChangeDirectory(ConfigurationManager.AppSettings("FTPWorkingDir"))

Dim fileNames As FtpList

fileNames = ftp.GetList()

Dim i As Integer

For i = 0 To (fileNames.Count - 1)

'Dim b As String

'b = fileNames.Item(i).Modified.Date.ToString()

If (fileNames.Item(i).Modified.Date.Equals(Today.Date)) Then

'Download file

todaysFileName = Now

todaysFileName = todaysFileName.Replace("/", "-")

todaysFileName = todaysFileName.Replace(":", "-")

ftp.GetFile(fileNames.Item(i).Name, Server.MapPath(ConfigurationManager.AppSettings("DownloadFolderName")) + todaysFileName + ".csv")

Exit For

End If

Next

End Function



No comments:

Post a Comment