我试过sftp程序使用sftp协议下载文件并使用下面的代码, 在这段代码的帮助下,我尝试使用SSH ftp下载文件。
我下载了必需的jscape jar文件并添加到构建路径中。它工作正常。一旦我执行,我得到了runtime >errors
import com.jscape.inet.sftp.Sftp;
import com.jscape.inet.sftp.SftpException;
import com.jscape.inet.sftp.events.SftpAdapter;
import com.jscape.inet.sftp.events.SftpDownloadEvent;
import com.jscape.inet.sftp.events.SftpConnectedEvent;
import com.jscape.inet.sftp.events.SftpDisconnectedEvent;
import com.jscape.inet.ssh.util.SshParameters;
public class sftpDownload extends SftpAdapter {
// perform multiple file download
public void doDownload(String sftpHostname, String sftpUsername, String sftpPassword, String filter)
throws SftpException
{
// create/initialize an Sftp instance
SshParameters params = new SshParameters(sftpHostname, sftpUsername, sftpPassword);
Sftp ftp = new Sftp(params);
//capture FTP related events when applicable (if your class extends SftpAdapter or implements FtpListener)
ftp.addSftpListener(this);
// establish connection
if(ftp.isConnected())
{
System.out.println("Connected");
ftp.disconnect();
//ftp.getFilePermissions(null);
}
else
{
ftp.connect();
}
// ftp.connect();
// download files matching filter
ftp.mdownload(filter);
// disconnect
ftp.disconnect();
}
// captures download event
public void download(SftpDownloadEvent evt) {
System.out.println("Downloaded file: " + evt.getFilename());
}
// captures connect event
public void connected(SftpConnectedEvent evt) {
System.out.println("Connected to server: " + evt.getHostname());
}
// captures disconnect event
public void disconnected(SftpDisconnectedEvent evt) {
System.out.println("Disconnected from server: " + evt.getHostname());
}
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter SFTP hostname : ");
String sftpHostname = reader.readLine().trim();
System.out.print("Enter SFTP username : ");
String sftpUsername = reader.readLine().trim();
System.out.print("Enter SFTP password : ");
String sftpPassword = reader.readLine().trim();
System.out.print("Enter download filter (eg .*\\.csv): ");
String filter = reader.readLine().trim();
sftpDownload load=new sftpDownload();
// do download
load.doDownload(sftpHostname, sftpUsername, sftpPassword, filter);
}
catch(Exception e) {
e.printStackTrace();
// e.getMessage();
}
}
}
一旦我提供了主机名,用户名,密码,过滤器,我就得到了
com.jscape.inet.sftp.SftpException
at com.jscape.inet.sftp.SftpConfiguration.createClient(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
and
Caused by: java.io.IOException '
请帮我处理上面的sftp代码,提前致谢
以下信息是我的输入页面,这里只传递主机名和其他信息的>要下载的文件类型等等。请澄清我的SFTP类型代码防火墙设置是否需要更改?如果是这样,请说明步骤......
Enter SFTP hostname : *.*.*.*
Enter SFTP username : *******
Enter SFTP password : password
Enter download filter (eg .*\.csv): *\.csv
com.jscape.inet.sftp.SftpException
at com.jscape.inet.sftp.SftpConfiguration.createClient(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
at com.jscape.inet.sftp.Sftp.connect(Unknown Source)
at com.test.file.sftpDownload.doDownload(sftpDownload.java:36)
at com.test.file.sftpDownload.main(sftpDownload.java:78)
Caused by: java.io.IOException
at com.jscape.inet.util.n.a(Unknown Source)
at com.jscape.inet.util.n.a(Unknown Source)
at com.jscape.inet.util.n.a(Unknown Source)
at com.jscape.inet.util.ConnectionParameters.createPlainSocket(Unknown Source)
at com.jscape.inet.util.ConnectionParameters.createSocket(Unknown Source)
at com.jscape.inet.ssh.transport.TransportClient.<init>(Unknown Source)
at com.jscape.inet.ssh.SshConfiguration.createConnectionClient(Unknown Source)
at com.jscape.inet.ssh.SshStandaloneConnector.openConnection(Unknown Source)
... 5 more