Open spmcewen opened 3 years ago
I think you are right there does look to be some issue with that statement It should perhaps be
SFTPv3FileAttributes attributes = client.stat(localFile)
But at the moment I am having some odd issues getting plugin to do a basic connection with this error: Caused by: java.io.IOException: Cannot negotiate, proposals do not match.
. this explains why
I think the library is now perhaps too old to work with current or more recent releases of ssh servers.
Is this plugin still working for you ? If so trying figure out how best I can port it over since the platform that it was released bintray
and entire plugin publish process has since changed
If I do upgrade it release it with what I am saying above I have no way of testing the code due to the ssh changes unless I roll ssh back to some ancient version.
There are a couple of things you could do :
import grails.plugin.remotessh.SSHUtil
import ch.ethz.ssh2.*
def someMethod() {
SSHUtil sshUtil = new SSHUtil().initialise('username', 'password', 'localhost', 22, false)
def fileExists = myfileExists(sshUtil, '/path/to/somefile')
}
boolean myfileExists(SSHUtil sshUtil, String filename) throws Exception {
boolean state=false
try {
SFTPv3FileAttributes attributes = sshUtil.client.stat(filename)
if (attributes != null) {
state=attributes.isRegularFile() || attributes.isDirectory()
} else {
state=false;
}
} catch (Exception e) {
state=false;
}
finaliseConnection()
return state
}
Or you could override class by having a class that overrides that method and declared in grails-app/conf/spring/resources.groovy
This tells your app to use MySshUtil as SShUtil I think you just need to extend SshUtil in that MySshUtil file which resides in your project and then override the given method
import grails.plugin.remotessh.SSHUtil
// Place your Spring DSL code here
beans = {
MySshUtil(SSHUtil)
}
Not quite sure it is worth upgrading plugin if current releases of ssh isn't going to work with library. I have another jssh
plugin I haven't tested that in ages either which uses sshtools:j2ssh
I recall someone else had done a plugin for jsch years back if that is not available on later releases of grails let me know and I can try make a new plugin
I was testing this plugin with a Grails 4 application and it did basically work for me. I was able to connect and copy a file to a SFTP server. However, overwriting or deleting an existing file doesn't work. I also noticed that this uses the very old and no loner maintained Ganymed SSH2 for Java library.
I switched to using the JSch library and it's sufficient for my simple needs.
Glad to hear you have something working, and yes it's down to original libraries used in the plugin which is why current limitations has come about. At the time jsch was also around and someone else had put together a plugin for it: grails-jsch-ssh2 - which is why I did another alternative using jssh and the alternative went a different route providing a ui so web interface could become like a console to interact with one or many hosts..
I see that jsch plugin hasn't been ported over to later versions of grails3+ so will probably sit down at some point and do a new ssh plugin based on those libraries and some re-usable methods of existing codes
At some point I was looking at jssh serving centralised methods for all 3 libraries as in what it does but for all 3 libraries Jsch ganymed and jssh as it does now.
https://github.com/vahidhedayati/RemoteSSH/blob/69122798ba86a3d993bd405b434d4990bf92b2d8/src/main/groovy/grails/plugin/remotessh/SSHUtil.groovy#L814
Should this be sending the path to the stat() call? Looking through the SFTPv3Client code it looks like it expects to have a path sent to it.