我尝试使用 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