Another possibility would be to extend the SFTP protocol, as this is something supported using the SSH_FXP_EXTENDED request. This could do the same thing but without requiring the creation of the new SSH channel. Though it's slightly more complicated as you need to enhance the SftpSubsystem implementation which does not support those extensions yet (patches welcomed !)
2014-11-13 8:18 GMT+01:00 Guillaume Nodet <[email protected]>: > I'm not sure how feasible that is on the server side, as afaik, the sftp > protocol does not allow transmitting such information from the client to > the server. > I think the file integrity is somewhat guaranteed by the underlying SSH > protocol which validates each packet, so the transmission errors are kinda > reduced to nothing. It leaves us with disk i/o read / write ... > Anyway, given the SFTP protocol does not really allow such a thing, maybe > an alternative way would be that the client sends a custom SSH command to > the server once the file has been completely written. It could send a > checksum of the file for verification and you could have the command do any > post processing. > > ClientSession session = client.connect(login, host, > port).await().getSession(); > session.auth().verify(); > > SftpClient sftp = session.createSftpClient(); > // write the file > ... > ChannelExec exec = session.createExecChannel("check mypath crc"); > exec.open().verify(); > exec.waitFor(ClientChannel.CLOSED, 0); > if (exec.getExitStatus() == null || exec.getExitStatus() != 0) { > throw new Exception("Transfer failed"); > } > > > For this to work, you simply need to implement a CommandFactory and the > check Command and register it on the server. > > This idea would work only if you control both the client and the server > obviously. As stated previously, I'm not sure there's any way to detect an > incomplete transfer from the server, but by using some kind of heuristic > based on the supposed client behavior. > > > 2014-11-13 2:48 GMT+01:00 Swaroop Rath <[email protected]>: > >> Hi Guillaume >> >> Thanks for your inputs, very helpful. >> >> The jira ticket mentions that there is no way of differentiating a >> successful upload from a cancelled one (cntl -c or network error). Am >> looking for a way to identify this. Ideally I would like to have a file >> integrity check in place to identify successful uploads and flag the ones >> which were cancelled or interrupted in between. >> >> Please let me know your thoughts on this ? >> >> - Swaroop Rath >> >> On 11/12/14, 5:45 AM, "Guillaume Nodet" <[email protected]> wrote: >> >> >The SFTP subsystem is implemented in the following class >> > >> > >> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_apache_min >> >> >a-2Dsshd_blob_master_sshd-2Dsftp_src_main_java_org_apache_sshd_sftp_subsys >> >> >tem_SftpSubsystem.java&d=AAIBaQ&c=izlc9mHr637UR4lpLEZLFFS3Vn2UXBrZ4tFb6oOn >> >> >mz8&r=ca1tqupLK4Jz1wonjGIDMOueMya8dUDvHzvROCFU2po&m=LCZSoj29kz80aYZFvuCn79 >> >u9lfQd8yuL2GwcjpyBXow&s=K0L973OxiWM4XbzK5wTVjoPnd8EtraInCN3LHS2Yyw8&e= >> > >> >However, there's really no callback supported at the moment, so the only >> >way would be to implement a custom FileSystemView and act when the >> >SshFile#handleClose() is called after one or more >> >SshFile#createOutputStream() calls. >> >A better alternative would be to actually modify the SftpSubsystem to >> >support such a thing. >> > >> >This is what has been captured in >> > >> https://urldefense.proofpoint.com/v2/url?u=https-3A__issues.apache.org_jir >> >> >a_browse_SSHD-2D108&d=AAIBaQ&c=izlc9mHr637UR4lpLEZLFFS3Vn2UXBrZ4tFb6oOnmz8 >> >> >&r=ca1tqupLK4Jz1wonjGIDMOueMya8dUDvHzvROCFU2po&m=LCZSoj29kz80aYZFvuCn79u9l >> >fQd8yuL2GwcjpyBXow&s=7LFyilgXzRHPW911X3tFz_0fyR2cIFFS0zl0ys4u-2A&e= . >> > >> > >> >2014-11-10 19:04 GMT+01:00 Swaroop Rath <[email protected]>: >> > >> >> Hi Guys >> >> >> >> I am using the Apache Mina SSHD project. I was able to start up and >> >>use a >> >> SFTP server. I want a method to be invoked every time a file transfer >> >> (copy) action is complete. >> >> >> >> I glanced through the docs and have not been able to find an answer. >> Any >> >> pointers in this direction would be really helpful. Am looking for the >> >> interfaces that I need to implement and the class/method where I need >> to >> >> register my call back function. >> >> >> >> Thanks in advance. >> >> Swaroop >> >> Software Dev, Palantir >> >> >> > >
