none
System.Net.WebException : The remote server returned an error: (550) File unavailable (e.g., file not found, no access) RRS feed

  • Question

  • I am using  FtpWebRequest to query the size of a file on an FTP site.   The code below generates the error message:

    System.Net.WebException : The remote server returned an error: (550) File unavailable (e.g., file not found, no access) listed.

     

    public long QuerySizeOfFile( string filename ) { if( String.IsNullOrEmpty( filename ) ) throw new ArgumentNullException( "filename" ); // _reset(); var uri = new Uri( _uri, filename ); var request = (FtpWebRequest) WebRequest.Create( uri ); request.Method = WebRequestMethods.Ftp.GetFileSize; request.Credentials = new NetworkCredential( _ftpSiteUserName, _ftpSitePassword ); long fileSize = 0; using( WebResponse response = request.GetResponse() ) { fileSize = response.ContentLength; } return fileSize; } private void _reset() { var request = (FtpWebRequest)WebRequest.Create( _uri ); request.Method = WebRequestMethods.Ftp.ListDirectory; request.Credentials = new NetworkCredential( _ftpSiteUserName, _ftpSitePassword ); using( var response = (FtpWebResponse)request.GetResponse() ) { } }

    private const string _ftpSitePassword = "123456";
    private const string _ftpSiteUserName = "myUserName";
    private static readonly Uri _uri = new Uri( "ftp://myDomainName.com" );

    Note: in the above code, the call to function '_reset()' is commented out in the 'QuerySizeOfFile()' function.    The problem reported occurs as long as '_reset' is commented out. 

    The problem reported is corrected/eliminated by UN-commenting the call to '_reset()' so that the function '_reset()' actually gets executed.

    My question is as follows:  What is the call to '_reset()' doing that corrects the problem?  For example, is '_reset()' somehow setting the root directory in the FTP site as the default directory?  Is the error occurring because I have not set appropriate FtpWebRequest members? 

    FYI: I wrote the function '_reset' after stumbling across this particular solution by trial and error.  It is currently a work around solution and I hope to be able to delete it once I have a better understanding of and more appropriate solution to the problem.

    Thanks,

    Ian


    • Edited by IB00 Tuesday, February 3, 2015 1:14 AM
    Tuesday, February 3, 2015 1:08 AM

Answers

All replies