Solved

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

Posted on 2006-07-07
7
510 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

630 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