0

I have in FTP server that will be created every 20 minutues and then deleted after certain time.I want to download file once it created and before deleting.I did like

while (!File.Exists(reqFTP.RequestUri.ToString()))
                                    {
                                        if (DateTime.Now > timeout)
                                        {

                                        }
                                        Thread.Sleep(TimeSpan.FromSeconds(1));
                                    }

But no luck at all every time File.Exists return false.Here is full code

string uri = "ftp://" + dtr["FTP_SERVER"].ToString() + "/" + remoteftppath;
                                    Uri serverUri = new Uri(uri);
                                    if (serverUri.Scheme != Uri.UriSchemeFtp)
                                    {
                                        return;
                                    }
                                    var timeout = DateTime.Now.Add(TimeSpan.FromMinutes(1));

                                    FtpWebRequest reqFTP;
                                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + dtr["FTP_SERVER"].ToString() + "/" + remoteftppath));
                                    reqFTP.Credentials = new NetworkCredential(dtr["FTP_USER_ID"].ToString(), dtr["FTP_PASSWORD"].ToString());
                                    reqFTP.KeepAlive = false;
                                    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                                    reqFTP.UseBinary = true;
                                    reqFTP.Proxy = null;
                                    reqFTP.UsePassive = false;
                                    while (!File.Exists(reqFTP.RequestUri.ToString()))
                                    {
                                        if (DateTime.Now > timeout)
                                        {

                                        }
                                        Thread.Sleep(TimeSpan.FromSeconds(1));
                                    }
                                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                                    responseStream = response.GetResponseStream();

I dont know what is went wrong.It is not at all coming out from loop

peter
  • 8,158
  • 21
  • 66
  • 119
  • I would have a look at the way you've arranged your logic - perhaps moving the loop would be of interest. In my opinion, you should handle file checking more like [`this`](http://stackoverflow.com/a/348334/5697616) – Gabe Mar 08 '16 at 01:49
  • there it is exception handling.For me my file will come every certain minutes and i have to download it .I don't want to go to exception – peter Mar 08 '16 at 05:27
  • Don't then - I would still look into how you've arranged your logic in the code above. – Gabe Mar 08 '16 at 05:30
  • Did you find any other method – peter Mar 08 '16 at 06:53

0 Answers0