C# getting file size of an FTP file in a while loop
<p>I am writing a program which lets me easily upload a file (drag file over exe) to my FTP server.</p>

<p>While the upload is in progress, I am trying to get the already uploaded file size in another thread.</p>

<p>This works exactly 2 times (caching?), then it just stops giving me feedback of the actual file size on the FTP server.</p>

<pre><code>System.Net.WebRequest req = System.Net.HttpWebRequest.Create(new Uri("http://drop.buto.ch/" + file));
req.Method = "HEAD";
System.Net.WebResponse resp = req.GetResponse();
int ContentLength;
if (int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength))
{
  return ContentLength;
}
</code></pre>

<p>or this</p>

<pre><code>System.Net.WebClient wc = new System.Net.WebClient();
wc.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
wc.Headers[HttpRequestHeader.CacheControl] = "no-cache";
wc.OpenRead(new Uri("http://drop.buto.ch/" + file));
Int64 bytes_total = Convert.ToInt32(wc.ResponseHeaders["Content-Length"]);
return bytes_total;
</code></pre>

<p>I have also tried achieving this with <code>WebRequestMethods.Ftp.GetFileSize</code> but this wouldn't let me access the file in Binary mode, instead its going over the ASCII way which is returning me an Error (550).</p>

<p>How can I get the file size on the FTP more than two times?</p>
