Exemple #1
0
        /// <summary>
        /// Determines the actual content length in a more reliable
        /// way for FTP downloads.
        /// </summary>
        /// <returns>-1 if no size could be determined</returns>
        private static long GetContentLength(WebResponse response)
        {
            HttpWebResponse http = response as HttpWebResponse;

            if (http != null)
            {
                return(http.ContentLength);
            }

            FtpWebResponse ftp = response as FtpWebResponse;

            if (ftp != null)
            {
                if (ftp.ContentLength > 0)
                {
                    return(ftp.ContentLength);
                }
                else
                {
                    // There is a problem with the .NET FTP implementation:
                    // "TYPE I" is never sent unless a file is requested, but is sometimes
                    // required by FTP servers to get the file size (otherwise error 550).
                    // Thus, we use a custom FTP library from code project for this task.
                    FTP ftpConnection = null;
                    try
                    {
                        ftpConnection = new FTP(response.ResponseUri.Host, "anonymous", "*****@*****.**");
                        return(ftpConnection.GetFileSize(response.ResponseUri.LocalPath));
                    }
                    catch (Exception)
                    {
                        // Limited trust in this code...
                        return(-1);
                    }
                    finally
                    {
                        if (ftpConnection != null)
                        {
                            ftpConnection.Disconnect();
                        }
                    }
                }
            }

            ScpWebResponse scp = response as ScpWebResponse;

            if (scp != null)
            {
                return(scp.ContentLength);
            }

            return(-1);
        }
Exemple #2
0
 /// <summary>
 /// Creates a new ScpWebResponse from the current request.
 /// </summary>
 /// <returns></returns>
 public override WebResponse GetResponse()
 {
     this.responseToAbort = new ScpWebResponse(this.requestUri, this.timeout);
     return(this.responseToAbort);
 }
Exemple #3
0
 /// <summary>
 /// Creates a new ScpWebResponse from the current request.
 /// </summary>
 /// <returns></returns>
 public override WebResponse GetResponse()
 {
     this.responseToAbort = new ScpWebResponse(this.requestUri, this.timeout);
     return this.responseToAbort;
 }