On Mon, Mar 14, 2011 at 1:33 PM, Mats Stromberg <[email protected]>wrote:
> That's worth to look at if it's allready in there... Still it doesn't
> explain how I can mess up such small template.
>
Got a chance to mess with this a bit. I dropped jsch-0.1.44.jar in
{jetty-openbd-root}/webapps/openbd/WEB-INF/lib and that's definitely the
right spot.
This code works:
<cfscript>
jsch = CreateObject("java", "com.jcraft.jsch.JSch").init();
WriteDump(jsch, "browser");
abort;
</cfscript>
So that shows it's instantiating the JSch class correctly.
Beyond that things get wonky rather quickly, particularly when you dig into
the mechanics of transferring files. In order to avoid wanting to shoot
yourself every time you did this you'd want to write some wrapper classes
and methods. Either I'm not that smart this evening or this is just really
nasty.
I think Denny's on the right track with the VFS suggestion in the short
term. Apache Commons VFS is included with OpenBD, so I took Denny's earlier
example and modified a bit and it works--this downloads a file over SFTP.
<cfscript>
fso = CreateObject("java",
"org.apache.commons.vfs.FileSystemOptions").init();
CreateObject("java",
"org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder").getInstance().setStrictHostKeyChecking(fso,
"no");
fsManager = CreateObject("java",
"org.apache.commons.vfs.VFS").getManager();
uri = "sftp://user:password@host:port/path/to/remote/File.cfc";
fo = fsManager.resolveFile(uri, fso);
bis = CreateObject("java",
"java.io.BufferedInputStream").init(fo.getContent().getInputStream());
fos = CreateObject("java",
"java.io.FileOutputStream").init("/local/path/to/write/File.cfc");
bos = CreateObject("java", "java.io.BufferedOutputStream").init(fos);
while ((c = bis.read()) != -1) {
bos.write(c);
}
bos.close();
fos.close();
fo.close();
fsManager.close();
</cfscript>
I did run into a bug with this code in that it works once but if you try to
run it again, you'll get the "unknown scheme" error outlined here (do a
ctrl-F for "unknown scheme"):
http://wiki.apache.org/commons/SimpleSftpFileDownload
Which appears to be addressable but not by me tonight at any rate. ;-) Hope
that at least gets you started.
Also please submit a ticket if you didn't already do so for SFTP support. Do
you care if it's in the CFFTP tag for compatibility with Adobe CF, or should
this be incorporated into CFFILE and SFTP is just another resource, or
something else people would like to see?
--
Matthew Woodward
[email protected]
http://blog.mattwoodward.com
identi.ca / Twitter: @mpwoodward
Please do not send me proprietary file formats such as Word, PowerPoint,
etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html
--
official tag/function reference: http://openbd.org/manual/
mailing list - http://groups.google.com/group/openbd?hl=en