Code example for File

Methods: getCanonicalPathgetName

0
    SftpClient sftp = null;
 
    try 
    { 
      sftp = getSftpClient();
      FileAttributes attr = sftp.stat(dir+"/"+local_file.getName());
 
      if(attr.isDirectory())
      { 
        JOptionPane.showMessageDialog(null, 
               "Cannot overwrite the directory\n"+ 
               dir+"/"+local_file.getName(),"Cannot Overwrite",
               JOptionPane.ERROR_MESSAGE); 
        return false; 
      } 
      else if(!force)
      { 
        int n = JOptionPane.showConfirmDialog(null,
               "Overwrite\n"+ 
               dir+"/"+local_file.getName() + "\n?",
               "Confirm the sequence entry", 
               JOptionPane.YES_NO_OPTION); 
        if(n == JOptionPane.NO_OPTION)
          return false; 
      }       
    } 
    catch(SshException sshe)
    { 
      if(System.getProperty("debug") != null)
      { 
        System.out.println("put() ");
        sshe.printStackTrace();
      } 
 
      rescue(); 
      return put(dir, local_file, monitor, force);
    } 
    catch(IOException ioe)
    { 
      // remote file doesn't exist 
    } 
 
    if(sftp == null)
      return false; 
 
      
    try 
    { 
      sftp.put(local_file.getCanonicalPath(), 
         dir+"/"+local_file.getName(), monitor);
      return true; 
    } 
    catch(SshException sshe)
    { 
      if(System.getProperty("debug") != null)
Experience pair programming with AI  Get Codota for Java