Don't we already use VFS?  I could be mistaken (I thought I saw it in
there), but theoretically, something like this would work:

http://commons.apache.org/vfs/filesystems.html#SFTP

Example code for copying a file:

public static void copyRemoteFile(String host, String user,
    String password, String remotePath, String localPath) throws IOException {
    // we first set strict key checking off
    FileSystemOptions fsOptions = new FileSystemOptions();
    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
            fsOptions, "no");
    // now we create a new filesystem manager
    DefaultFileSystemManager fsManager = (DefaultFileSystemManager) VFS
            .getManager();
    // the url is of form sftp://user:pass@host/remotepath/
    String uri = "sftp://"; + user + ":" + password + "@" + host
            + "/" + remotePath;
    // get file object representing the local file
    FileObject fo = fsManager.resolveFile(uri, fsOptions);
    // open input stream from the remote file
    BufferedInputStream is = new BufferedInputStream(fo.getContent()
            .getInputStream());
    // open output stream to local file
    OutputStream os = new BufferedOutputStream(new FileOutputStream(
            localPath));
    int c;
    // do copying
    while ((c = is.read()) != -1) {
        os.write(c);
    }
    os.close();
    is.close();
    // close the file object
    fo.close();
    // NOTE: if you close the file system manager, you won't be able to
    // use VFS again in the same VM. If you wish to copy multiple files,
    // make the fsManager static, initialize it once, and close just
    // before exiting the process.
    fsManager.close();
    System.out.println("Finished copying the file");
}

I'm not sure how cffile is set up (id est, using VFS?), but I bet we
could leverage some existing infrastructure somewhere...

:Den

-- 
Love is something far more than desire for sexual intercourse; it is
the principal means of escape from the loneliness which afflicts most
men and women throughout the greater part of their lives.
Bertrand Russell

On Mon, Mar 14, 2011 at 12:58 PM, Mats Stromberg wrote:
> I'm just testing the Jcraft jsch library but failing on the first line :)
>
> import com.jcraft.jsch.*;
>
> Package com.jcraft.jsch does not exists.
>
> I do test this on a Jetty installationand I put the jsch-0.1.44.jar in
> the wepapps/openbd/WEB-INF/ib folder
>
> I suppose this is the correct place for an add-on .jar ? or am I
> missing it again :)
>
> /Mats/

-- 
official tag/function reference: http://openbd.org/manual/
 mailing list - http://groups.google.com/group/openbd?hl=en

Reply via email to