首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过zehon.jar连接到SFTP

通过zehon.jar连接到SFTP
EN

Stack Overflow用户
提问于 2014-02-04 18:20:17
回答 1查看 935关注 0票数 0

我正在尝试连接到本地主机上的SFTP服务器。我从泽洪网站做了例子,但我有一些错误。我使用freeSSHd作为我的SFTP服务器,例如在fileZilla中它工作得很好。

sftptest.java

代码语言:javascript
运行
复制
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) {}}
        }
    }

}

以及我在启动app时的错误:

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2014-02-04 18:24:16

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21549650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档