通过zehon.jar连接到SFTP

时间:2014-02-04 10:20:17

标签: java sftp

我正在尝试连接到localhost上的SFTP服务器。我从zehon网站做了例子,但我有一些错误。我使用freeSSHd作为我的SFTP服务器,它在fileZilla中运行良好。

sftptest.java

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import com.zehon.exception.FileTransferException;
import com.zehon.sftp.SFTP;



public class sftptest {

    public static void main(String[] args) throws FileNotFoundException {
        // TODO Auto-generated method stub

        InputStream is = null;
        String filePath = "C:/DATA/echo.txt";
        File localFile = new File(filePath);        
        is = new BufferedInputStream(new FileInputStream(localFile));
        String destFolder = "/";
        String nameOfFile = "echo.txt";
        int status = -1;
        try {

            status = SFTP.sendFile(is, nameOfFile, destFolder,"127.0.0.1", "test", "test" );
        } catch (FileTransferException e) {
            e.printStackTrace();
            //or
            //ex.getCause().printStackTrace();  (
            //Depending on what version of JDK you use)         
        }finally{
            if(is != null){try {is.close();} catch (IOException e) {}}
        }
    }

}

以及我在启动应用时的错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/vfs/FileSystemException
    at com.zehon.sftp.SFTP.getSFTPClient(SFTP.java:20)
    at com.zehon.sftp.SFTP.sendFile(SFTP.java:110)
    at pl.wn.sftpzehon.sftptest.main(sftptest.java:29)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.vfs.FileSystemException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 3 more

1 个答案:

答案 0 :(得分:0)

确保Apache Commons VFS在您的类路径中。

相关问题