Java 通过zehon.jar连接到SFTP
我正在尝试连接到本地主机上的SFTP服务器。我在zehon网站上做了一个例子,但我有一些错误。我使用freeshd作为我的SFTP服务器,它在fileZilla中工作良好 sftptest.javaJava 通过zehon.jar连接到SFTP,java,sftp,Java,Sftp,我正在尝试连接到本地主机上的SFTP服务器。我在zehon网站上做了一个例子,但我有一些错误。我使用freeshd作为我的SFTP服务器,它在fileZilla中工作良好 sftptest.java import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOExcept
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
确保在类路径中。确定。谢谢,这还不行,因为这是问题之一,现在我需要另一个库。