FtpWebRequest error: 550 Size not allowed in ASCII mode RRS feed

  • Question

  • User-926160538 posted

    Hi I have following problem while get File Size from the FTP path after file upload in specific FTP connection not all .

    Exception Message : "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."

    Inner Exception is : FtpWebRequest error: 550 Size not allowed in ASCII mode.

    I have used following code to fetch FTP File size.

    if (objFtpState.StatusDescription.Contains("Transfer complete"))
          req = (FtpWebRequest)FtpWebRequest.Create(txtUrl.Text + FileName);
          req.Credentials = new NetworkCredential(txtUser.Text, txtFTPPassword.Text);
          req.Method = WebRequestMethods.Ftp.GetFileSize();
           wresponse = (FtpWebResponse)req.GetResponse();
      catch (WebException ex)
       FtpWebResponse response = (FtpWebResponse)ex.Response;
           if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                lblMsg.Text = "File not found in the FTP folder. Please contact administrator";
                lblMsg.ForeColor = Color.Red;


    After changing piece of code from   req.Method = WebRequestMethods.Ftp.GetFileSize();  to  req.UseBinary = true; req.Method = WebRequestMethods.Ftp.DownloadFile; working without exception.

    1.What configuration required in FTP connection to work existing code. ?

    2.How it's working when download file ?

    Please give me your valuable solution.

    Tuesday, July 17, 2018 6:44 AM

All replies

  • User36583972 posted

    Hi Pandiyan,

    1.What configuration required in FTP connection to work existing code. ?

    2.How it's working when download file ?

    You can ask the server how big the file is so you can keep track of the download percentage later on. Here are the two C# lines to modify this time:

    FtpWebRequest request = FtpWebRequest.Create([FTPAddress]) as FtpWebRequest;
    request.Method = WebRequestMethods.Ftp.ListDirectory;

    if your FTP address like: ftp://myserver.com/myfile.txt, you can ask the FTP server for the filesize:

    int dataLength = (int)request.GetResponse().ContentLength;

    For more detailed : C# Download File FTP

    The following links for your reference.

    How to: Download files with FTP:

    Download File From FTP With Sub-Directories Using C#:

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Yong Lu

    Wednesday, July 18, 2018 6:00 AM