You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-users@mina.apache.org by Faseela Mohamed <fa...@gmail.com> on 2017/02/17 22:27:37 UTC

Restricting hidden files to upload

Hi

Is there a way to restrict the hidden files to be uploaded in to the
folders.
Right now I am deleting the hidden file on onUploadStart and onUploadEnd
methods. It still upload the file and deletes. Is there an option to
restrict certain types of files. Any help is appreciated .. Thanks

    public FtpletResult onUploadStart(FtpSession session, FtpRequest
request)
            throws FtpException, IOException {
            System.out.println("User uploaded FtpServer");
        List< ? extends FtpFile > ftpFileList =
session.getFileSystemView().getWorkingDirectory().listFiles();
        for (FtpFile ftpFile :ftpFileList ){
            System.out.println(ftpFile.getName());
            if (defaultLogin.equals(session.getUser())) ftpFile.delete();
            if(ftpFile.isHidden()) {
                ftpFile.delete();
                return FtpletResult.SKIP;
            }
        }
        return super.onUploadStart(session, request);
    }

Re: Restricting hidden files to upload

Posted by Faseela Mohamed <fa...@gmail.com>.
Or a "REFRESH " of session.getFileSystemView().getWorkingDirectory() will
be also helpful.

On Fri, Feb 17, 2017 at 2:27 PM, Faseela Mohamed <fa...@gmail.com>
wrote:

> Hi
>
> Is there a way to restrict the hidden files to be uploaded in to the
> folders.
> Right now I am deleting the hidden file on onUploadStart and onUploadEnd
> methods. It still upload the file and deletes. Is there an option to
> restrict certain types of files. Any help is appreciated .. Thanks
>
>     public FtpletResult onUploadStart(FtpSession session, FtpRequest
> request)
>             throws FtpException, IOException {
>             System.out.println("User uploaded FtpServer");
>         List< ? extends FtpFile > ftpFileList =
> session.getFileSystemView().getWorkingDirectory().listFiles();
>         for (FtpFile ftpFile :ftpFileList ){
>             System.out.println(ftpFile.getName());
>             if (defaultLogin.equals(session.getUser())) ftpFile.delete();
>             if(ftpFile.isHidden()) {
>                 ftpFile.delete();
>                 return FtpletResult.SKIP;
>             }
>         }
>         return super.onUploadStart(session, request);
>     }
>

Re: Restricting hidden files to upload

Posted by Faseela Mohamed <fa...@gmail.com>.
Thanks for the inputs ... To avoid even go to onUploadStart() , I used the
below method. ..


 else if ("STOR".equals(command)) {
            if (defaultLogin.equals(session.getUser()) ) return
FtpletResult.DISCONNECT;



*if (reqLine.contains("STOR .")){                System.out.println("User
upload HIDDEN FILE   ");                 return FtpletResult.SKIP;
    }*
            return onUploadStart(session, request);
        }

On Mon, Feb 20, 2017 at 4:20 AM, Gary Bell <ga...@aero.bombardier.com>
wrote:

> Sorry, didn't read the OP properly. I would agree with John. I do
> something similar in my code.
>

RE: Restricting hidden files to upload

Posted by Gary Bell <ga...@aero.bombardier.com>.
Sorry, didn't read the OP properly. I would agree with John. I do something similar in my code.

Re: Restricting hidden files to upload

Posted by John Hartnup <jo...@gmail.com>.
Do you want to forbid upload of hidden files?

I think if your onUploadStart() sends a `550 Permission Denied` response,
then returns SKIP, you'll achieve that goal. You would not need to delete
the file, as it would never get created.

You would need a different way to tell if the file is hidden than
File.isHidden() -- because you would not yet have a file. On UNIX, it's
just a filename starting with a dot.



On Mon, Feb 20, 2017 at 9:31 AM Gary Bell <ga...@aero.bombardier.com>
wrote:

> I would look at overriding the NativeFtpFile.listFiles() method to achieve
> this. The filesystem is pluggable and comes with a native filesystem
> implementation by default; but you can implement your own and therefore
> obtain whatever functionality you need.
>

RE: Restricting hidden files to upload

Posted by Gary Bell <ga...@aero.bombardier.com>.
I would look at overriding the NativeFtpFile.listFiles() method to achieve this. The filesystem is pluggable and comes with a native filesystem implementation by default; but you can implement your own and therefore obtain whatever functionality you need.