Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have some code that needs to process a file that is FTP'd to a folder on a server. So I wrote a windows service using the FileSystemWatcher. If I just move a file into that directory it works perfectly, but if a file is FTP'd there it doesn't fire. I read somewhere that it doesn't work with FTP. Is that true? Here is my code:
m_Watcher = new System.IO.FileSystemWatcher();
m_Watcher.Path = strfolder;
m_Watcher.Filter = "*.xml";
m_Watcher.NotifyFilter = NotifyFilters.FileName;
m_Watcher.Created += new FileSystemEventHandler(OnCreated);
m_Watcher.EnableRaisingEvents = true;

Any suggestions?

Thanks
Posted

Interesting issue... I have a folder monitoring application that uses the FileSystemWatcher, so I just did a quick test downloading a small file and a large file using WS_FTP Pro into a folder I was monitoring, and both triggered the Created and Changed events.

So, seems to me it "should" work... unless there is an issue with either being a windows service app, or a different ftp program?

One thing to note in my test, however, is that if you FTP a larger file, the Created event is triggered at the beginning of the download... but bytes keep flowing into that file after that event, so that may cause issues depending on what you plan on doing when you detect a new file.

Good luck!
 
Share this answer
 
Comments
swbo102 3-Jun-11 8:30am    
The FTP protocol that the file being sent is FTP/SSL (FTPS), so I'm wondering if that has anything to do with it. The size of the files are fairly small, but I did think about the issue if it triggering prior to the completed transfer. However, when debugging, the trigger never tripped. Thanks for your comment!
There is nothing even close to the ability to deliver any events from FTP server to a client. There is no a sign of inversion of control (see http://en.wikipedia.org/wiki/Inversion_of_control[^]) you might need for that. FTP protocol is very old, based on purely client-server paradigm and completely closed for any extensions, callback or anything like that.

You have only one remote possibility: you can develop a custom service on the server machine instead of FTP or in addition to it. This cannot be a pure client-server technology, but should be based on a published-subscriber paradigm: clients are connected to the service and subscribe to certain notifications from the service file system. If the service is Window-based, you can use FileSystemWatcher inside the server machine.

This is quite feasible, but would make a pretty serious project which would take considerable development time. I'm not sure it can interest you. If you're are interested, ask your questions (use "Add comment" and "Improve question", don't post a "solution" as many mistakenly do), but don't expect easy solution.

—SA
 
Share this answer
 
Comments
swbo102 3-Jun-11 8:32am    
My only other alternative, which isn't great, was just to build a 15 second timer in the service to keep polling the folder. Worst case I may end up with that. I'll keep researching. Thanks!
Sergey Alexandrovich Kryukov 5-Jun-11 22:56pm    
It's exactly as bad as polling. I don't think your search will find you anything, by the reasons I explained.
You should better formally accept my answer. If it does not solve you problem does not mean it's wrong.
Thank you,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900