Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-07-07
7
Medium Priority
?
516 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to dynamically set the form action using jQuery.
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

721 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