Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET webservice - Connect to FTP Web server - Read Text file.

Posted on 2006-07-07
7
Medium Priority
?
521 Views
Last Modified: 2011-09-20
EE Team,

I have a project design, wherein i need to develop a asp.net web service application, this application will constantly look in to a FTP Server.

So other application will place a text file on to the Secure FTP Server, and my webservice will look for this text file, if the text file is found, it will read this file and update some table.

The problem here is what kind of programming method should i use, please give me some examples..from web....

1. Web service to connect to FTP Server.
2. How the web service will know, if there is any text file in the folder.
3. How to read the text file.

Please let me know you thought or sample example how can i acheive this design.

Thanks
0
Comment
Question by:Apu_Shah
  • 3
4 Comments
 
LVL 3

Expert Comment

by:mdg12
ID: 17066998
There are several examples on the web...  Take for example the API at
http://www.csharphelp.com/archives/archive9.html

Copy the first class into FTPFactory.cs
Then in your webservice method, do something like the following
   FTPFactory ff = new FTPFactory();
   ff.setRemoteHost("192.168.0.30");
   ff.setRemoteUser("username");
   ff.setRemotePass("password");
   ff.login();
   ff.chdir("/dir");
   
   // Check if file exists
   String[] fileNames = ff.getFileList("filename.txt");
   if (fileNames==null || fileNames.Length!=1) {
     // File not found
     return;
   }
   
   // File is there, download it
   ff.setBinaryMode(true);
   ff.download("filename.txt");
   
   // Remove it??
   ff.deleteRemoteFile("filename.txt");
   
   ff.close();
   
   DoSomethingWithFile();
0
 
LVL 2

Author Comment

by:Apu_Shah
ID: 17068876
I looked at this code, i think it will work as expected.

I had one more question : The design says " Webservice will always loop and look for a one text file. if the file is found continue read the file and process " I am not sure how will this code make sure to loop and look for the file and once the file is arrived at the ftp server - folder location. process it.

I am going to try this, also i need help or sample code - to read a tab delimited text files.

Thanks.
0
 
LVL 3

Accepted Solution

by:
mdg12 earned 2000 total points
ID: 17070302
I'm not positive I understand the design (and certainly not the rationale), but here's an example of how you might loop until you find the file...

Also at the end is a sample of how you might load the file to begin processing it.  I'm not sure what sort of processing you'll need to do, but below shows you how to read it line by line.. After that, you'll probably want to use either string functions or regular expressions

   FTPFactory ff = new FTPFactory();
   ff.setRemoteHost("192.168.0.30");
   ff.setRemoteUser("username");
   ff.setRemotePass("password");
   ff.login();
   ff.chdir("/dir");
   
   while (true)
   {
      // Check if file exists
      string[] fileNames = ff.getFileList("filename.txt");
      if (fileNames==null || fileNames.Length!=1) {
        // File not found, loop again
        continue;
      }
        // File exists, proceed
        break;
   }
   
   // File is there, download it
   ff.setBinaryMode(true);
   ff.download("filename.txt");
   
   // Remove it from remote server??
   ff.deleteRemoteFile("filename.txt");
   
   ff.close();
   
   // Load the local file
   StreamReader re = File.OpenText("filename.txt");
   string line = null;
   while ((line = re.ReadLine()) != null) {
      //TODO: Process line
   }
   re.close;




References:
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=132
http://www.csharphelp.com/archives/archive9.html
0
 
LVL 3

Expert Comment

by:mdg12
ID: 17471310
pinaldave - I don't mean to be a pointwhore, but I think my responses answered his question...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question