* @throws ServerException
* @throws ClientException
* @throws IOException
*/
public void transfer(URI srchost, URI desthost, GSSCredential gssCred, boolean srcActive) throws ToolsException {
GridFTPClient destClient = null;
GridFTPClient srcClient = null;
try {
destClient = new GridFTPClient(desthost.getHost(), desthost.getPort());
destClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
destClient.authenticate(gssCred);
makeExternalConfigurations(destClient, false);
if (checkBinaryExtensions(desthost.getPath())) {
log.debug("Transfer mode is set to Binary");
destClient.setType(Session.TYPE_IMAGE);
}
srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort());
srcClient.setAuthorization(new HostAuthorization(GridFtp.HOST));
srcClient.authenticate(gssCred);
makeExternalConfigurations(srcClient, true);
if (checkBinaryExtensions(srchost.getPath())) {
log.debug("Transfer mode is set to Binary");
srcClient.setType(Session.TYPE_IMAGE);
}
if (srcActive) {
log.debug("Set src active");
HostPort hp = destClient.setPassive();
srcClient.setActive(hp);
} else {
log.debug("Set dst active");
HostPort hp = srcClient.setPassive();
destClient.setActive(hp);
}
log.debug("Start transfer file from GridFTP:" + srchost.toString() + " to " + desthost.toString());
/**
* Transfer a file. The transfer() function blocks until the transfer is complete.
*/
srcClient.transfer(srchost.getPath(), destClient, desthost.getPath(), false, null);
if (srcClient.getSize(srchost.getPath()) == destClient.getSize(desthost.getPath())) {
log.debug("CHECK SUM OK");
} else {
log.debug("****CHECK SUM FAILED****");
}
} catch (ServerException e) {
throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+ desthost.toString(), e);
} catch (IOException e) {
throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+ desthost.toString(), e);
} catch (ClientException e) {
throw new ToolsException("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+ desthost.toString(), e);
} finally {
if (destClient != null) {
try {
destClient.close();
} catch (Exception e) {
log.warn("Cannot close GridFTP client connection at Desitnation:" + desthost.toString());
}
}
if (srcClient != null) {
try {
srcClient.close();
} catch (Exception e) {
log.warn("Cannot close GridFTP client connection at Source:" + srchost.toString(),e);
}
}
}