throw new ConfigException(e);
}
}
protected ChannelSftp getOrCreateChannel(ResourceURI uri) {
final ResourceKey key = new ResourceKey(uri);
ChannelSftp channel;
synchronized (channels) {
channel = (ChannelSftp) channels.get(key);
if (channel == null) {
try {
ResourceContext.get().setCurrentURI(uri.getURI());
com.jcraft.jsch.Session session = jsch.getSession(key.getUser(), key.getHost(), key.getPort());
session.setUserInfo(new UserInfo() {
private UsernamePassword up;
public String getPassphrase() {
return null;
}
public boolean promptPassphrase(String message) {
return true;
}
public String getPassword() {
return up == null ? null : up.getPassword();
}
public boolean promptPassword(String message) {
URI uri = ResourceContext.get().getCurrentURI();
String username = ResourceContext.get().getCurrentUsername();
Set visitedURIs = ResourceContext.get().getVisitedURIs();
message = "\nAuthentication required: \n" + uri + "\n";
up = getResourceManager().getAuthenticationHandler().authenticate(message, uri, username,
visitedURIs.contains(key));
visitedURIs.add(key);
return up != null;
}
public boolean promptYesNo(String str) {
return true;
}
public void showMessage(String message) {
}
});
session.connect();
channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
String charset = uri.getOption("charset");
if (charset != null) {
channel.setFilenameEncoding(charset);
}
channels.put(key, channel);
// �ɹ���������Ա����ظ���ʾ��������
ResourceContext.get().getVisitedURIs().remove(new ResourceKey(new ResourceURI(uri.getURI())));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new ConfigException(e);
} finally {