I have been working on a small project on and off for a while and I think I am close but it has 'issues'. The idea is to FTP a file up to a 3rd party, they process it and 5-10 minutes later they generate a result set which needs to get downloaded and processed on our side.
So the code might be a little simple, it's just something I cobbled together
if (!Page.IsPostBack) { string baseLocation = "C:\\temp\\"; string fn = baseLocation + "fxxxupld.inc"; ftp = new FtpClient(FTPServer, FTPUserName, FTPPassword); ftp.Login(); ftp.Upload(fn); AsyncCallback callback = new AsyncCallback(CloseConnection); ftp.ChangeDir("results"); string[] Files = ftp.GetBloombergUploadList(); int CHigh = Files.GetUpperBound(0); String LatestFile = CheckForNewFile(CHigh, ftp); ftp.BeginDownload(LatestFile, "c:\\temp\\Results.txt", callback); } private static string CheckForNewFile(int CHigh,FtpClient ftp) { int NHigh = 0; string LatestFile = ""; while (CHigh >= NHigh) { string[] Files = ftp.GetBloombergUploadList(); NHigh = Files.GetUpperBound(0); LatestFile = Files[NHigh-1].ToString(); Thread.Sleep(3000); } return LatestFile; } private void CloseConnection(IAsyncResult result) { Debug.WriteLine("File downloaded: " + result.IsCompleted.ToString()); if (ftp != null) ftp.Close(); ftp = null; }
Pretty simple, push the file up, get a list of the currently processed files, wait and check every so often and when a new file shows up, download it.
Before I added the AsyncCallback in, the process worked fine except the user couldn't do anything until the page returned and I couldn't display any kind of progress indicator, etc. After adding in the AsyncCallback all of a sudden the UPLOAD part is spamming the remote end and I managed to crash them (or at least our particular connection).
Any thoughts on it would be appreciated... needly to say I sort of need to get the process fixed right because our traders get a little upset when they can't work and Bloomberg gets a little upset when they have to spend 3+ hours trying to resolve it :(
thanks!