Auto-reconnect and SetWorkingDirectory

Feb 23, 2015 at 6:06 PM
I have an application using System.Net.FtpClient which runs 24/7, every few minutes it connects to an ftp server, does a SetWorkingDirectory, uploads a few files, and then disconnects.

It appears that when I have connection issues in the middle of the uploads, the session gets automatically reconnected, which is nice, but it means that the remaining files get uploaded to the wrong directory.

Is my assessment correct, and if so, is there anything I can do? Perhaps I should avoid using SetWorkingDirectory, and I should append the path to the front of the remote filename instead?

Feb 24, 2015 at 5:15 AM
Hi Steve,

The best solution for now is going to be to use absolute paths. You are right that System.Net.FtpClient doesn't remember the working directory between reconnects. You could modify it to save it to a protected clone-able property (check some of the other properties to see the attribute) in the FtpClass and have the Connect method check it and set it as needed. It needs the clone attribute added so that if you use the thread safe data channels feature the working directory gets copied over to new instances of FtpClient created internally.
Feb 24, 2015 at 9:14 AM
Thanks - I'll go with the absolute paths and maybe look at modifying it later when I have more time.