Program: 81032
Project: 81032
Buggy source:
public synchronized static boolean upload(String server,String username,String password,String directory,int port,boolean useFtps,String protocol,boolean implicit,File gpxFile,String fileName){
  FTPClient client;
  try {
    if (useFtps) {
      client=new FTPSClient(protocol,implicit);
      KeyManagerFactory kmf=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      kmf.init(null,null);
      KeyManager km=kmf.getKeyManagers()[0];
      client.setSocketFactory(Networks.getSocketFactory(AppSettings.getInstance()));
      ((FTPSClient)client).setKeyManager(km);
    }
 else {
      client=new FTPClient();
    }
  }
 catch (  Exception e) {
    jobResult=new UploadEvents.Ftp().failed("String_Node_Str",e);
    LOG.error("String_Node_Str",e);
    return false;
  }
  try {
    client.connect(server,port);
    logServerReply(client);
    if (client.login(username,password)) {
      client.enterLocalPassiveMode();
      logServerReply(client);
      LOG.debug("String_Node_Str" + server);
      LOG.debug("String_Node_Str" + directory);
      FTPFile[] existingDirectory=client.listFiles(directory);
      logServerReply(client);
      if (existingDirectory.length <= 0) {
        LOG.debug("String_Node_Str" + directory);
        ftpCreateDirectoryTree(client,directory);
        logServerReply(client);
      }
      FileInputStream inputStream=new FileInputStream(gpxFile);
      client.changeWorkingDirectory(directory);
      client.setFileType(FTP.BINARY_FILE_TYPE);
      boolean result=client.storeFile(fileName,inputStream);
      inputStream.close();
      logServerReply(client);
      if (result) {
        LOG.debug("String_Node_Str" + fileName);
      }
 else {
        jobResult=new UploadEvents.Ftp().failed("String_Node_Str" + fileName,null);
        LOG.debug("String_Node_Str" + fileName);
        return false;
      }
    }
 else {
      logServerReply(client);
      jobResult=new UploadEvents.Ftp().failed("String_Node_Str",null);
      LOG.debug("String_Node_Str");
      return false;
    }
  }
 catch (  Exception e) {
    logServerReply(client);
    jobResult=new UploadEvents.Ftp().failed("String_Node_Str",e);
    LOG.error("String_Node_Str",e);
    return false;
  }
 finally {
    try {
      client.logout();
      logServerReply(client);
      client.disconnect();
      logServerReply(client);
    }
 catch (    Exception e) {
      if (jobResult == null) {
        jobResult=new UploadEvents.Ftp().failed("String_Node_Str",e);
      }
      LOG.error("String_Node_Str",e);
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
public synchronized static boolean upload(String server,String username,String password,String directory,int port,boolean useFtps,String protocol,boolean implicit,File gpxFile,String fileName){
  FTPClient client;
  try {
    if (useFtps) {
      client=new FTPSClient(protocol,implicit);
      KeyManagerFactory kmf=KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      kmf.init(Networks.getKnownServersStore(AppSettings.getInstance()),null);
      KeyManager km=kmf.getKeyManagers()[0];
      ((FTPSClient)client).setKeyManager(km);
      ((FTPSClient)client).setTrustManager(Networks.getTrustManager(AppSettings.getInstance()));
    }
 else {
      client=new FTPClient();
    }
  }
 catch (  Exception e) {
    jobResult=new UploadEvents.Ftp().failed("String_Node_Str",e);
    LOG.error("String_Node_Str",e);
    return false;
  }
  try {
    client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(new LoggingOutputStream(LOG))));
    client.setDefaultTimeout(60000);
    client.setConnectTimeout(60000);
    client.connect(server,port);
    client.setSoTimeout(60000);
    client.setDataTimeout(60000);
    logServerReply(client);
    if (client.login(username,password)) {
      if (useFtps) {
        ((FTPSClient)client).execPBSZ(0);
        logServerReply(client);
        ((FTPSClient)client).execPROT("String_Node_Str");
        logServerReply(client);
      }
      client.enterLocalPassiveMode();
      logServerReply(client);
      LOG.debug("String_Node_Str" + server);
      LOG.debug("String_Node_Str" + directory);
      FTPFile[] existingDirectory=client.listFiles(directory);
      logServerReply(client);
      if (existingDirectory.length <= 0) {
        LOG.debug("String_Node_Str" + directory);
        ftpCreateDirectoryTree(client,directory);
        logServerReply(client);
      }
      FileInputStream inputStream=new FileInputStream(gpxFile);
      client.changeWorkingDirectory(directory);
      client.setFileType(FTP.BINARY_FILE_TYPE);
      boolean result=client.storeFile(fileName,inputStream);
      inputStream.close();
      logServerReply(client);
      if (result) {
        LOG.debug("String_Node_Str" + fileName);
      }
 else {
        jobResult=new UploadEvents.Ftp().failed("String_Node_Str" + fileName,null);
        LOG.debug("String_Node_Str" + fileName);
        return false;
      }
    }
 else {
      logServerReply(client);
      jobResult=new UploadEvents.Ftp().failed("String_Node_Str",null);
      LOG.debug("String_Node_Str");
      return false;
    }
  }
 catch (  Exception e) {
    logServerReply(client);
    jobResult=new UploadEvents.Ftp().failed("String_Node_Str",e);
    LOG.error("String_Node_Str",e);
    return false;
  }
 finally {
    try {
      client.logout();
      logServerReply(client);
      client.disconnect();
      logServerReply(client);
    }
 catch (    Exception e) {
      if (jobResult == null) {
        jobResult=new UploadEvents.Ftp().failed("String_Node_Str",e);
      }
      LOG.error("String_Node_Str",e);
      return false;
    }
  }
  return true;
}