title: Using “put” command in sftp gives No such file or directory 3: Permission denied
body: <p>I'm trying to retrieve some files from sftp server using JSch but I'm getting the following error.</p>
  
  <pre><code>ls: cannot access /export/user-docs/adminuser/record/WAQ12.txt: No such file or directory
      3: Permission denied, file: /opt/ftp/pub/new_waq_std/WAQ12.txt
      @at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
      @at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:768)
      @at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:709)
      @at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:703)
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>class WSFTPFile {
         static WSFTPFile ftpFile =null;
          private static ChannelSftp sftp;
          private static Session jschSession;
         WSDBTool dbTool= null;
             boolean stickyCRLF=false;
             boolean seenCR=false;
  
         public static WSFTPFile getInstance(){
             if (ftpFile == null)
                ftpFile =  new WSFTPFile();
             return ftpFile;
         }
  
         public void performFTP(Vector&lt;String&gt; v) throws Exception {
  
               /*SFTP Coding start */
              int authResult = -1;
               JSch jsch = new JSch();
  
              try{
  
              jsch.addIdentity(dbTool.getSourceDirectory()
                      + "id_rsa_1234.wsadmin");
  
              jschSession = (Session) jsch.getSession(dbTool.getFTPUserName(),
                      dbTool.getFTPIP(), 22);
              Properties config = new Properties();
              config.put("StrictHostKeyChecking", "no");
              jschSession.setConfig(config);
              jschSession.connect();
              System.out.println("Host connected.");
  
              }catch(Exception e) {
                  System.out.println("Exception in connecting to SFTP server.");
                  e.printStackTrace();
              }
              // SftpClient sftp;
              System.out.println("authResult:" + authResult);
  
                  if (jschSession.isConnected()) {    
                  try{
                      sftp = (ChannelSftp)jschSession.openChannel("sftp") ;
                      sftp.connect();
                      //sftp = sshClient.openSftpClient();
                      sftp.lcd(dbTool.getSourceDirectory());
                      sftp.cd(dbTool.getFileDirectory());
  
                      sftp.put(dbTool.getSourceDirectory()+dbTool.getFileName(),dbTool.getFileName(),ChannelSftp.OVERWRITE);
                      if(sftp != null) {
                          sftp.disconnect();  
                          sftp.quit();
                          sftp = null;
                      }
                      System.out.println("Successfully connected to ws  SFTP area..");
                  }catch(Exception e){
                      System.out.println("Exception in SFTP put.");
                      e.printStackTrace();
                  }
              }else{
                  System.out.println("Error connecting SFTP server.");
              }
                  if(jschSession != null){
                       jschSession.disconnect();
                       jschSession = null;
                  }
               /*SFTP Coding END*/
              System.out.println("File sent to ws  via SFTP");
          }
          }
  </code></pre>
  
  <p>Below is what i get when i run ls -alF in the ftp directory:-</p>
  
  <p>-rw-r--r-- 1 ssrftp ssssftp 3135 May 16 17:00 WAQ12.txt</p>
  
  <p>But my existing WAQ12.txt is like 2 months old in the ftp location and it gives me the above error while trying to do ftp. Does the date of the file matters? Any idea?
    NOTE:- For testing, i deleted the existing WAQ12.txt in the location /export/user-docs/adminuser/record/WAQ12.txt and ran my program , it worked fine and populated the file  WAQ12.txt in the ftp location and again when i ran the program it did overwrite the previous WAQ12.txt and the timestamp got updated.</p>
  
  <p>But i don't want to that, i want the previous WAQ12.txt(which is 2 months old) file to be overwritten by the new file when i run my program, but i am keep getting the above error. Any idea?</p>