我正在使用以下代码建立 SSH 连接并通过 curl 将文件下载到 SSH 服务器。它给了我一个没有消息的例外。目前还不确定该怎么做。
try{
JSch jsch=new JSch();
String host=selectedItem.getHost();
String user="down2home";
int port = selectedItem.getPort();
String password = selectedItem.getPass();
String dlurl = dlurlField.getText().toString();
Session session=jsch.getSession(user, host, port);
session.setPassword(password);
UserInfo ui = new MyUserInfo(){
};
ByteArrayOutputStream out = new ByteArrayOutputStream();
String command = "curl -L --create-dirs -o /home/paul/Desktop/geeknights/geeknights.mp3 "+dlurl+"\r\n";
out.write(command.getBytes());
out.flush();
InputStream in = new ByteArrayInputStream(out.toByteArray());
session.setUserInfo(ui);
session.connect(30*1000); // making a connection with timeout.
Channel channel=session.openChannel("shell");
channel.setInputStream(in);
channel.setOutputStream(System.out);
channel.connect(3*1000);
}
catch(Exception e){
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Exception:", errorMessage );
}
追溯:
06-08 00:33:16.561: E/Exception:(9293): Message is empty