Re: SFTP with Commons VFS

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: SFTP with Commons VFS

manco
go to shell.java the test program that comes with vfs
and make these mods - look at the StrictHost
references
below. You may not want to do this in the long run as
it is a bit less secure, but it may get you past your
first hurdle.

manco

    /**
     * Does a 'cp' command.
     */
    private void cp(final String[] cmd) throws
Exception
    {
        if (cmd.length < 3)
        {
            throw new Exception("USAGE: cp <src>
<dest>");
        }
        // Testing for Sftp
        FileSystemOptions opts = new
FileSystemOptions();
       
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
           opts, "no");
        String cking =
SftpFileSystemConfigBuilder.getInstance().getStrictHostKeyChecking(
               opts );
        //FileObject file = mgr.resolveFile(args[i],
opts);
        final FileObject src = mgr.resolveFile(cwd,
cmd[1]);
        //final FileObject src =
mgr.resolveFile(cwd.getName() + cmd[1], opts);
        //FileObject dest = mgr.resolveFile(cwd,
cmd[2]);
        FileObject dest = mgr.resolveFile(cmd[2],
opts);

        if (dest.exists() && dest.getType() ==
FileType.FOLDER)
        {
            dest =
dest.resolveFile(src.getName().getBaseName());
        }

        dest.copyFrom(src, Selectors.SELECT_ALL);
    }

--- Abner Novak Pitinga <[hidden email]> wrote:

> Hi,
>  
> I'm trying to use VFS to do a connection with a SFTP
> server.
>  
> Do you have any example working to show me?
>  
> Here is my example, but it does not work....
>  
> Can you help me?
>  
> Java Code
> ================
> public class VFSTeste {
>
>     public static void main(String[] args) {
>
>         FileSystemOptions fso = null;
>
>         DefaultFileSystemManager fsm = null;
>
>         SftpFileProvider sftp = null;
>
>         SftpFileSystem fstpFS = null;
>
>         try {
>
>             fso = new FileSystemOptions();
>
>
>
>  
>
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso,

> "no");
>
>
>
>             fsm = new DefaultFileSystemManager();
>
>
>
>             sftp = new SftpFileProvider();
>
>             sftp.init();
>
>
>
>             fsm.addProvider("sftp", sftp);
>
>             fsm.init();
>
>
>
>             SftpFileObject fo = (SftpFileObject)
> fsm.resolveFile("sftp://user:pass@HOST/file.sql",
> fso);
>
>             System.out.println(fo.getName());
>
> } catch (FileSystemException e) {
>
>                 e.printStackTrace();
>
>           } finally{
>
>                 sftp.close();
>
>                 fsm.close();
>
>             }
>
>        }
>
> }
>
> ================
>  
> Stack Trace
> ================
> org.apache.commons.vfs.FileSystemException: Could
> not connect to SFTP server
> at "sftp://user:pass@host/".
>
> at
>
org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(Sft
> pFileProvider.java:87)
>
> at
>
org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(Abs
> tractOriginatingFileProvider.java:76)
>
> at
>
org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(Abs
> tractOriginatingFileProvider.java:61)
>
> at
>
org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFile
> SystemManager.java:513)
>
> at
>
org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFile
> SystemManager.java:466)
>
> at
>
com.tlantic.teste.vfs.VFSTeste.main(VFSTeste.java:61)
>
> Caused by:
> org.apache.commons.vfs.FileSystemException: Could
> not connect to
> SFTP server at "10.51.100.169".
>
> at
>
org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(Sftp
> ClientFactory.java:166)
>
> at
>
org.apache.commons.vfs.provider.sftp.SftpFileProvider.doCreateFileSystem(Sft

> pFileProvider.java:79)
>
> ... 5 more
>
> Caused by: com.jcraft.jsch.JSchException: Auth fail
>
> at com.jcraft.jsch.Session.connect(Unknown Source)
>
> at com.jcraft.jsch.Session.connect(Unknown Source)
>
> at
>
org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(Sftp
> ClientFactory.java:162)
>
> ... 6 more
>
> ================
>



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]