Click here to Skip to main content
15,891,921 members
Home / Discussions / C#
   

C#

 
GeneralI need your reviews. [modified] Pin
massu_vago25-Feb-09 23:24
massu_vago25-Feb-09 23:24 
GeneralRe: I need your reviews. Pin
Cracked-Down25-Feb-09 23:30
Cracked-Down25-Feb-09 23:30 
GeneralRe: I need your reviews. Pin
Eddy Vluggen26-Feb-09 3:36
professionalEddy Vluggen26-Feb-09 3:36 
QuestionResizing window changes User control's top left position Pin
AksharRoop25-Feb-09 23:14
AksharRoop25-Feb-09 23:14 
AnswerRe: Resizing window changes User control's top left position Pin
Shyam K Pananghat25-Feb-09 23:19
Shyam K Pananghat25-Feb-09 23:19 
GeneralRe: Resizing window changes User control's top left position Pin
AksharRoop26-Feb-09 0:05
AksharRoop26-Feb-09 0:05 
AnswerRe: Resizing window changes User control's top left position Pin
#realJSOP25-Feb-09 23:54
mve#realJSOP25-Feb-09 23:54 
QuestionProblem with downloading file from FTP through HTTP-proxy [modified] Pin
STeAlth-S25-Feb-09 23:11
STeAlth-S25-Feb-09 23:11 
While downloading files from FTP-server through HTTP-proxy I've met the following problem: sometimes there are some zero bytes in the begin of the response (62 or 63 bytes),the end of the stream was truncated by the same count of bytes.

But the bug is not constant. If I try to download file without proxy, everything is fine.

What can be the reason of this problem and how to solve it?

Here is some code that I use to download files.

    Uri srcURI = new Uri(SourceURL);
    if (srcURI.Scheme != Uri.UriSchemeFtp)
        throw new Exception("URL has invalid format");
    FtpWebRequest webReq = (FtpWebRequest)(WebRequest.Create(srcURI));
    webReq.Method = WebRequestMethods.Ftp.DownloadFile;
    webReq.Timeout = 5000;
    webReq.ReadWriteTimeout = 10000;
    webReq.UseBinary = true;
    webReq.UsePassive = true;
    webReq.KeepAlive = false;
    webReq.Proxy = proxy;
    webReq.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

    try
    {
        FtpWebResponse webResp=(FtpWebResponse)(WebReq.GetResponse());
        if (webResp.ContentLength == -1)
            throw new Exception(string.Format("Can't download file: {0}",
                WebReq.RequestUri.Segments[WebReq.RequestUri.Segments.Length - 1]));

        string fname = WebReq.RequestUri.Segments[WebReq.RequestUri.Segments.Length - 1];
        OnUpdateDownloadStatus(string.Format("Downloading file {0}", fname), -2);

        string path = string.Format(@"{0}\{1}", DestFolder,
            fname);
        Stream fs = File.Open(path, FileMode.Create);
        int cnt = 0;
        using (BinaryWriter bw = new BinaryWriter(fs))
        {
            byte[] buf = new byte[ChunkSize];
            using (Stream s = webResp.GetResponseStream())
            {
                do
                {
                    if (AbortDownload)
                        throw new Exception("Downloading was canceled");

                    cnt = s.Read(buf, 0, ChunkSize);
                    bw.Write(buf, 0, cnt);
                    int percent = (int)(bw.BaseStream.Length * 100 / webResp.ContentLength);
                    OnUpdateDownloadStatus(
                        string.Format("Downloading file {0} : {1} %", fname, percent), percent);
                }
                while (cnt > 0);
            }
        }
    }
    catch (Exception exc)
    {
        StatusMessage=exc.Message;
    }
    finally
    {
        if (webResp != null)
            webResp.Close();
        OnDownloadComplit(StatusMessage);
    }
}


modified on Thursday, February 26, 2009 6:33 AM

AnswerRe: Problem with downloading file from FTP through HTTP-proxy Pin
STeAlth-S4-Mar-09 0:02
STeAlth-S4-Mar-09 0:02 
QuestionString to char* in DLL Pin
leslie wu25-Feb-09 23:11
leslie wu25-Feb-09 23:11 
AnswerRe: String to char* in DLL Pin
Shyam K Pananghat25-Feb-09 23:25
Shyam K Pananghat25-Feb-09 23:25 
AnswerRe: String to char* in DLL [modified] Pin
Jimmanuel26-Feb-09 3:17
Jimmanuel26-Feb-09 3:17 
AnswerRe: String to char* in DLL Pin
PIEBALDconsult26-Feb-09 4:16
mvePIEBALDconsult26-Feb-09 4:16 
GeneralRe: String to char* in DLL Pin
leslie wu26-Feb-09 4:18
leslie wu26-Feb-09 4:18 
Questionpc processes Pin
shefa' isied25-Feb-09 23:07
shefa' isied25-Feb-09 23:07 
AnswerRe: pc processes Pin
Shyam K Pananghat25-Feb-09 23:17
Shyam K Pananghat25-Feb-09 23:17 
QuestionWhy integer occupying 16 bytes instead of 4 bytes? Pin
Sandeep Kalra25-Feb-09 23:07
Sandeep Kalra25-Feb-09 23:07 
AnswerRe: Why integer occupying 16 bytes instead of 4 bytes? Pin
Eddy Vluggen26-Feb-09 3:37
professionalEddy Vluggen26-Feb-09 3:37 
Questionprocess tracing Pin
lost_in_code25-Feb-09 23:06
lost_in_code25-Feb-09 23:06 
QuestionHow to get Printing text Pin
Joe Rozario25-Feb-09 23:00
Joe Rozario25-Feb-09 23:00 
Questiongenerate variables at runtime ? Pin
Mubeen.asim25-Feb-09 22:59
Mubeen.asim25-Feb-09 22:59 
AnswerRe: generate variables at runtime ? [modified] Pin
Shyam K Pananghat25-Feb-09 23:10
Shyam K Pananghat25-Feb-09 23:10 
GeneralRe: generate variables at runtime ? Pin
Mubeen.asim25-Feb-09 23:12
Mubeen.asim25-Feb-09 23:12 
AnswerRe: generate variables at runtime ? Pin
Eddy Vluggen25-Feb-09 23:31
professionalEddy Vluggen25-Feb-09 23:31 
GeneralRe: generate variables at runtime ? Pin
Shyam K Pananghat26-Feb-09 0:18
Shyam K Pananghat26-Feb-09 0:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.