Home > Net >  C#/.net to download the exe file on the FTP server "cache" problem! How to solve?
C#/.net to download the exe file on the FTP server "cache" problem! How to solve?

Time:10-19


Problem: the server with another exe file, part of the client before you download or exe (most of the clients normal)
Under the same path method to download the exe file normal!!!!!!!!!!!!!!!

Is the client or server problems?
Is a code or a client computer problems?
String UpdateFile=lvUpdateList. Items [I] Text. The Trim ();
String updateFileUrl=updateUrl + lvUpdateList. Items [I] Text. The Trim ();
Long fileLength=0;

WebRequest webReq=WebRequest. Create (updateFileUrl);
WebResponse webRes=webReq. The method GetResponse ();
FileLength=webRes. ContentLength;

LbState. Text="is download the update file, please later... ";
PbDownFile. Value=https://bbs.csdn.net/topics/0;
PbDownFile. Maximum=(int) fileLength;

The Stream SRM=webRes. GetResponseStream ();
StreamReader srmReader=new StreamReader (SRM);
Byte [] bufferbyte=new byte [fileLength];
Int allByte=(int) bufferbyte. Length;
Int startByte=0;
While (fileLength & gt; 0)
{
Application.doevents ();
Int downByte=SRM. Read (bufferbyte startByte, allByte);
{if (downByte==0) break; };
StartByte +=downByte;
AllByte -=downByte;
PbDownFile. Value +=downByte;

Float part=(float) startByte/1024;
Float total=(float) bufferbyte. Length/1024;
Int percent=the Convert. ToInt32 ((part/total) * 100);

This. LvUpdateList. Items [I]. SubItems [2]. The Text=percent. The ToString () + "%".

}

String tempPath=tempUpdatePath + UpdateFile;
CreateDirtory (tempPath);
FileStream fs=new FileStream (tempPath, FileMode OpenOrCreate, FileAccess. Write);
Fs. Write (bufferbyte, 0, bufferbyte. Length);
SRM. The Close ();
SrmReader. Close ();
Fs. The Close ();

CodePudding user response:

The simplest solution is updateFileUrl=updateFileUrl + "?" + DateTime. Now. ToString (" yyyyMMddHHmmss ");

Add a timestamp to URL parameters, change the URL, so there is no cache

CodePudding user response:

You use the get request? Get request with the browser cache problem, so either you behind the parameters with a timestamp, or change to a post, or you download address to designated by your handler returns, do not use the browser cache specified in the return

CodePudding user response:

Url behind increasing timestamp, and random Numbers can be,

CodePudding user response:

You this way! Feeling should be the problem of network agents

I use ie IP directly download 59. XXX. Xx. X/XXX file but ie return file under another IP


Also called?

CodePudding user response:

reference 1st floor jinkuang45 response:
the simplest solution is updateFileUrl=updateFileUrl + "?" + DateTime. Now. ToString (" yyyyMMddHHmmss ");

Add a timestamp to URL parameters, change the URL, so there is no cache of possible
. This method can't see me downstairs figure.

CodePudding user response:

refer to the second floor she would play the soy sauce response:
get request you use? Get request with the browser cache problem, so either you behind the parameters with a timestamp, or change to a post, or to download your address designated by your handler returns, specified in the return does not use the browser cache
. This method can't see me downstairs figure.
  •  Tags:  
  • C#
  • Related