Logo Search packages:      
Sourcecode: jftp version File versions  Download package

int net::sf::jftp::net::FtpConnection::exists ( String  file  )  [inline]

Checks wheter a file exists.

Parameters:
file the name of the file
Returns:
An int-code: CHDIR_FAILED, PERMISSION_DENIED (no listing allowed), R, W or DENIED

Definition at line 2581 of file FtpConnection.java.

References chdir(), net::sf::jftp::net::FtpConstants::CHDIR_FAILED, net::sf::jftp::net::FtpConstants::FILE_NOT_FOUND, getCachedPWD(), getPermissions(), list(), net::sf::jftp::net::FtpConstants::PERMISSION_DENIED, and sortLs().

    {
        String dir = null;
        String tmpPWD = getCachedPWD();

        if(file.indexOf("/") >= 0)
        {
            dir = file.substring(0, file.lastIndexOf("/") + 1);
            Log.out("checking dir: " + dir);

            if(!chdir(dir))
            {
                return CHDIR_FAILED;
            }
        }

        try
        {
            list();
        }
        catch(IOException ex)
        {
            ex.printStackTrace();

            return PERMISSION_DENIED;
        }

        String f = file.substring(file.lastIndexOf("/") + 1);
        Log.out("checking file: " + f);

        String[] files = sortLs();
        int[] perms = getPermissions();

        int y = -1;

        for(int x = 0; x < files.length; x++)
        {
            if(files[x].equals(f))
            {
                y = x;

                break;
            }
        }

        if(y == -1)
        {
            return FILE_NOT_FOUND;
        }

        if(dir != null)
        {
            chdir(tmpPWD);
        }

        return perms[y];
    }


Generated by  Doxygen 1.6.0   Back to index