+ ftp.getReplyString());
}
}
public void doFTP() throws BuildException {
FTPClient ftp = null;
try {
task.log("Opening FTP connection to " + task.getServer(), Project.MSG_VERBOSE);
ftp = new FTPClient();
if (task.isConfigurationSet()) {
ftp = FTPConfigurator.configure(ftp, task);
}
ftp.setRemoteVerificationEnabled(task.getEnableRemoteVerification());
ftp.connect(task.getServer(), task.getPort());
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
throw new BuildException("FTP connection failed: "
+ ftp.getReplyString());
}
task.log("connected", Project.MSG_VERBOSE);
task.log("logging in to FTP server", Project.MSG_VERBOSE);
if ((task.getAccount() != null && !ftp.login(task.getUserid(), task.getPassword(), task.getAccount()))
|| (task.getAccount() == null && !ftp.login(task.getUserid(), task.getPassword()))) {
throw new BuildException("Could not login to FTP server");
}
task.log("login succeeded", Project.MSG_VERBOSE);
if (task.isBinary()) {
ftp.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
throw new BuildException("could not set transfer type: "
+ ftp.getReplyString());
}
} else {
ftp.setFileType(org.apache.commons.net.ftp.FTP.ASCII_FILE_TYPE);
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
throw new BuildException("could not set transfer type: "
+ ftp.getReplyString());
}
}
if (task.isPassive()) {
task.log("entering passive mode", Project.MSG_VERBOSE);
ftp.enterLocalPassiveMode();
if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
throw new BuildException("could not enter into passive "
+ "mode: " + ftp.getReplyString());
}
}
// If an initial command was configured then send it.
// Some FTP servers offer different modes of operation,
// E.G. switching between a UNIX file system mode and
// a legacy file system.
if (task.getInitialSiteCommand() != null) {
RetryHandler h = new RetryHandler(task.getRetriesAllowed(), task);
final FTPClient lftp = ftp;
executeRetryable(h, new Retryable() {
public void execute() throws IOException {
doSiteCommand(lftp, task.getInitialSiteCommand());
}
}, "initial site command: " + task.getInitialSiteCommand());
}
// For a unix ftp server you can set the default mask for all files
// created.
if (task.getUmask() != null) {
RetryHandler h = new RetryHandler(task.getRetriesAllowed(), task);
final FTPClient lftp = ftp;
executeRetryable(h, new Retryable() {
public void execute() throws IOException {
doSiteCommand(lftp, "umask " + task.getUmask());
}
}, "umask " + task.getUmask());
}
// If the action is MK_DIR, then the specified remote
// directory is the directory to create.
if (task.getAction() == FTPTask.MK_DIR) {
RetryHandler h = new RetryHandler(task.getRetriesAllowed(), task);
final FTPClient lftp = ftp;
executeRetryable(h, new Retryable() {
public void execute() throws IOException {
makeRemoteDir(lftp, task.getRemotedir());
}
}, task.getRemotedir());
} else if (task.getAction() == FTPTask.SITE_CMD) {
RetryHandler h = new RetryHandler(task.getRetriesAllowed(), task);
final FTPClient lftp = ftp;
executeRetryable(h, new Retryable() {
public void execute() throws IOException {
doSiteCommand(lftp, task.getSiteCommand());
}
}, "Site Command: " + task.getSiteCommand());