title: Java SFTP upload using JSch, but how to overwrite the current file?
body: <p>I am trying to upload two files to a server with SFTP using JSch. It works fine to upload the files if the directory is empty but I want to upload the same file over and over (just changing an id inside) but I can't figure out how to do this. There is some static parameter in JSch called OVERWRITE but I can't find out how to use it.</p>
  
  <p>Anyone care to show me how I should add this setting?</p>
  
  <p>This is my current code:</p>
  
  <pre><code>public void upload() {
    try {
      JSch jsch = new JSch();
  session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
  session.setPassword(SFTPPASS);
  java.util.Properties config = new java.util.Properties();
  config.put("StrictHostKeyChecking", "no");
  session.setConfig(config);
  session.connect();
  channel = session.openChannel("sftp");
  channel.connect();
  channelSftp = (ChannelSftp) channel;
  channelSftp.cd(SFTPWORKINGDIR);
  
      File f1 = new File("ext_files/" + FILETOTRANSFER1);
  channelSftp.put(new FileInputStream(f1), f1.getName());
  File f2 = new File("ext_files/" + FILETOTRANSFER2);
  channelSftp.put(new FileInputStream(f2), f2.getName());
  
  channelSftp.exit();
  session.disconnect();
  } catch (Exception ex) {
    ex.printStackTrace();
    }
  }
  </code></pre>