Created
December 29, 2009 12:51
-
-
Save kiy0taka/265295 to your computer and use it in GitHub Desktop.
Groovy/Commons VFS/SFTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('commons-vfs:commons-vfs:1.0') | |
@Grab('com.jcraft:jsch:0.1.42') | |
import com.jcraft.jsch.* | |
import org.apache.commons.vfs.* | |
import org.apache.commons.vfs.provider.sftp.* | |
def url = 'sftp://username@host[:port]/path' | |
def keyFilePath = 'path/to/keyfile' | |
def passphrase = 'passphrase' | |
def fileSystemManager = VFS.manager | |
if (!fileSystemManager.hasProvider('sftp')) { | |
fileSystemManager.addProvider('sftp', new SftpFileProvider()) | |
} | |
def opts = new FileSystemOptions() | |
SftpFileSystemConfigBuilder.getInstance().with { | |
it.setStrictHostKeyChecking(opts, "no"); | |
it.setIdentities(opts, [new File(keyFilePath)] as File[]) | |
it.setUserInfo(opts, [getPassphrase:{passphrase}, promptPassphrase:{true}] as UserInfo) | |
} | |
fileSystemManager.resolveFile(url, opts).children.each { | |
println it.name | |
} |
madmas , not true, groovy-vfs has 30 issues , none resolved , not very active, examples fail , typical example of developer wanting to much , achieving less .... here i have a example that works
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have a look at https://github.com/ysb33r/groovy-vfs, it makes such things with groovy a lot simpler :)