try {
in = retrieveFileStream(remoteFile);
// boolean test = retrieveFile(remoteFile, new FileOutputStream( new File(localFile+"test"), append ));
if (in == null) {
throw new JobSchedulerException("Could not open stream for " + remoteFile + ". Perhaps the file does not exist. Reply from ftp server: "
+ getReplyString());
}
if (isPositiveCommandCompletion() == false) {
throw new JobSchedulerException("..error occurred in getFile() [retrieveFileStream] on the FTP server for file [" + remoteFile + "]: "
+ getReplyString());
}
// TODO Buffersize must be an Option
byte[] buffer = new byte[4096];
out = new FileOutputStream(new File(localFile), append);
// TODO get progress info
int bytes_read = 0;
synchronized (this) {
while ((bytes_read = in.read(buffer)) != -1) {
out.write(buffer, 0, bytes_read);
out.flush();
totalBytes += bytes_read;
}
}
in.close();
out.close();
if (!completePendingCommand()) {
logout();
disconnect();
throw (new JobSchedulerException("File transfer failed."));
}
if (isNegativeCommandCompletion()) {
throw new JobSchedulerException("..error occurred in getFile() on the FTP server for file [" + remoteFile + "]: " + getReplyString());
}
if (totalBytes > 0)
return totalBytes;
else
return -1L;