3

In my application, I download files in network drive to local and then process them.

Now my problem is network path changed from windows to ftp and need user id password to access that.

My application code is in C# and which can not accomodate this change directly, how do I take care of this within code -- with minimal effort.

Thanks

Sam Hosseini
  • 813
  • 2
  • 9
  • 17
jjj
  • 31
  • 1

2 Answers2

1

The easiest way to use ftp in your app is to get one of the many ftp client packages. At work we use the Xceed ftp client and it seems to work fine, although it is a little pricey. Here is an open source project I found by googling for .NET FTP Client:

http://www.codeproject.com/KB/IP/FtpClient.aspx

Brent Stewart
  • 1,830
  • 14
  • 21
0

Add an interface (say IFileHandler) which defines the contract for the getting of the remote file, then implement what you currently have, to get from a network drive, behind one implementation of that interface (say called NetworkFileHandler).

Then create a second implementation (say FtpFileHandler) of that interface that gets the file from FTP site. In the second implementation you give the extra information (username and password) to the constructor of the FtpFileHandler class.

Then to change the app to do one or the other you just need to change which implementation of the interface you use.

This would then allow you to add other ways of getting the file in the future like BitTorrentFileHandler for getting files from a bittorrent source or NntpFileHandler for downloading the files from a newsgroup.

The interface IFileHandler could look something like:

interface IFileHandler
{
   void SaveFileLocally(string sourceFile, DirectoryInfo targetLocation);
}

although exactly what it should look like will depend on what you need to do.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181