How to find server folder has access denied ?

0 votes
asked Jan 5, 2015 by ganeshspy (900 points)
edited Jan 6, 2015

How to find server folder has access denied ? Related to FTP SFTP.

if server folder is access denied then i am getting

550 Permission Denied

exception error and code is 550 but same error code is used for folder not found

Applies to: Rebex FTP/SSL, Rebex SFTP

1 Answer

0 votes
answered Jan 5, 2015 by Tomas Knopp (58,890 points)
edited Jan 6, 2015

In the case of such errors in FTP protocol, the status of the FtpException is set to ProtocolError. So use a try catch block and look for the FtpException with such status. Then you can access the FTP response code and message via properties (see code below).

    Ftp ftp = new Ftp();
    // connect and login

    try
    {
            // some FTP operation
            ftp.Rename("nonExistingFolder", "folderNew");
    }
    catch (FtpException ex)
    {
            if (ex.Status == FtpExceptionStatus.ProtocolError)
            {
                    // use the following properties to report what is going on:
                    Console.WriteLine(ex.Response.Code);
                    Console.WriteLine(ex.Response.Description);
                    Console.WriteLine(ex.Response.Raw);
            }
    }

Unfortunately, the FTP protocol only returns a code and a message and there is not one easy recipe to differentiate whether it is "access denied", "folder not found" or other error, as the messages can be different for each server and each 'problem type'. So we do not provide API for this. If you are using only a few particular servers, you might and the error codes are the same, you might test the error description and distinguish based on that. But if you plan to support any FTP server, then a suggested behavior is to report/ log the error and let the user decide what to do.

commented Jan 5, 2015 by ganeshspy (900 points)
edited Jan 5, 2015

currently i am doing like this..

but more server is there then it not work. (",)

okay thank for support....

commented Jan 6, 2015 by Tomas Knopp (58,890 points)
edited Jan 6, 2015

Hello, could you please describe in more details what exactly is not working for you?

...