The only issue with throwing IOException is that it is a checked exception, and the interface method FileSystemView#getFile(String file) doesn't declare it, so I have to change the interface to throw it.
I'll take a look at isReadable, etc., but my code short-circuits the process way ahead of that, by just looking at the path the user is attempting, and if it is a substring of the directory I want to pin them in, then I know they shouldn't be going there, and I throw the exception. Regards, Davis -----Original Message----- From: Guillaume Nodet [mailto:[email protected]] Sent: Monday, September 12, 2011 12:10 PM To: [email protected] Subject: Re: sftp questions RIght, but most blocks handling specific questions catch IOException and sent back a better error code without closing the whole channel: case SSH_FXP_xxx: { try { // implementation } catch (IOException e) { sendStatus(id, SSH_FX_FAILURE, e.getMessage()); } break; So if you throw an IOException it should work. Also, for reading / writing files, you can override isReadable() and isWritable() and sftp will sent back error codes like SSH_FX_PERMISSION_DENIED. On Mon, Sep 12, 2011 at 17:53, Davis Ford <[email protected]> wrote: > Hi Guillaume, as far as I can tell stepping through the code, the exception > is swallowed and logged in SftpSubsystem.java lines 372-375: > > } catch (Throwable t) { > if (!closed && !(t instanceof EOFException)) { // Ignore han > log.error("Exception caught in SFTP subsystem", t); > } > } finally { > > This is in the public SftpSubsystem#run() method. The stacktrace is like > this, my exception trickles up and is caught in the run() method. > > SftpSubsystem.run() > SftpSubsystem.process() > FileSystemView.getFile() > > -----Original Message----- > From: Guillaume Nodet [mailto:[email protected]] > Sent: Monday, September 12, 2011 11:47 AM > To: [email protected] > Subject: Re: sftp questions > > I think the message on the exception is sent back to the user, but > currently > there's no way to return a different error code than SSH_FX_FAILURE. > I suppose we could define an exception containing the error code and use it > if such an exception is caught. > > On Mon, Sep 12, 2011 at 17:10, Davis Ford <[email protected]> wrote: > > > Ok, I figured this out by implementing my own FileSystemView interface, > and > > related interfaces, and I can detect when a user tries to cd .. up to a > > parent dir -- if I detect this, I'm just throwing a RuntimeException and > the > > client just gets an error indicating the SFTP command was not received. > > > > Technically this works, but it isn't clear to me how to do this > gracefully > > so they would get some kind of permissions error. > > > > This is in my own implementation of FileSystemView#getFile(String file) > > which returns SshFile. Is there some way to code this, so the Sftp > > subsystem will return some kind of auth or permissions error to the > client? > > > > -----Original Message----- > > From: Davis Ford > > Sent: Friday, September 09, 2011 3:42 PM > > To: '[email protected]' > > Subject: RE: sftp questions > > > > Guillame -- Thanks for the info, appreciate it. One other quick > follow-up > > if I may - is there an easy way to pin a client into a specific directory > > for uploads? > > > > > > > > > -- > ------------------------ > Guillaume Nodet > ------------------------ > Blog: http://gnodet.blogspot.com/ > ------------------------ > Open Source SOA > http://fusesource.com > -- ------------------------ Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ Open Source SOA http://fusesource.com
