⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sftpdeploymentprovider.java

📁 SFTP Plug-in for Eclipse will add the SFTP support to Eclipse
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        "SFTPDeploymentProvider.4", url.toExternalForm()), null); //$NON-NLS-1$  }  private int getTimeout(URL url) throws TeamException{    return getSFTPSite(url).getTimeout();  }  /* (non-Javadoc)   * @see com.jcraft.eclipse.team.internal.sftp.client.ISFTPRunnableContext#getOpenClient()   */  public IClient getOpenClient(){    return getConnectedClient();  }  public IResourceVariant getResourceVariant(IResource resource,      byte[] syncBytes) throws TeamException{    try{      if(syncBytes==null)        return null;      return SFTPSubscriberResource.create(this, getUrl(resource), syncBytes);    }    catch(MalformedURLException e){      SFTPPlugin.logError(Policy.bind(          "SFTPDeploymentProvider.5", resource.getFullPath().toString()), e); //$NON-NLS-1$      return null;    }  }  /* (non-Javadoc)   * @see org.eclipse.team.core.target.TargetDeploymentProvider#run(org.eclipse.team.internal.core.target.ITargetRunnable, org.eclipse.core.runtime.IProgressMonitor)   */  public void run(final ITargetRunnable runnable, IProgressMonitor monitor)      throws TeamException{    final TeamException[] exception=new TeamException[] {null};    run(new ISFtpRunnable(){      public void run(IProgressMonitor monitor) throws SFtpException{        try{          SFTPDeploymentProvider.super.run(runnable, monitor);        }        catch(TeamException e){          exception[0]=e;        }      }    }, monitor);    if(exception[0]!=null){      throw exception[0];    }  }  /* (non-Javadoc)   * @see org.eclipse.team.core.target.TargetDeploymentProvider#putFile(org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor)   */  public void putFile(final IFile localFile, IProgressMonitor monitor)      throws TeamException{    final TeamException[] exception=new TeamException[] {null};    run(new ISFtpRunnable(){      public void run(IProgressMonitor monitor) throws SFtpException{        try{          putFile(getOpenClient(), getRelativePath(localFile).toString(),              localFile, Team.getType(localFile)!=Team.TEXT, monitor);        }        catch(SFTPException e){          exception[0]=e;        }      }    }, monitor);    if(exception[0]!=null){      throw exception[0];    }  }  /**   * Stores a local file on the remote system.   * @param filePath the absolute or relative path of the file   * @param localFile the local file to send   * @param binary if true, uses binary transfer type   * @param monitor the progress monitor, or null   */  public void putFile(IClient client, String filePath, IFile localFile,      boolean binary, IProgressMonitor monitor) throws SFTPException{    InputStream in=null;    try{      in=new BufferedInputStream(localFile.getContents());      SFtpTargetResource.putFile(client, filePath, in, getFileSize(localFile),          binary, monitor);    }    catch(CoreException e){      throw SFTPException.wrapException(Policy          .bind("SFTPClient.ErrorSendingFile"), e); //$NON-NLS-1$    }    finally{      if(in!=null)        try{          in.close();        }        catch(IOException e1){          // Ignore exceptions on close;        }    }  }  /* (non-Javadoc)   * @see org.eclipse.team.core.target.TargetDeploymentProvider#deleteRemote(org.eclipse.core.resources.IResource, org.eclipse.core.runtime.IProgressMonitor)   */  public void deleteRemote(IResource resource, IProgressMonitor monitor)      throws TeamException{    try{      if(resource.getType()==IResource.FILE){        getOpenClient().deleteFile(getRelativePath(resource).toString(),            monitor);      }      else{        getOpenClient().deleteDirectory(getRelativePath(resource).toString(),            monitor);      }    }    catch(SFtpException e){      throw SFTPException.wrapException(e);    }  }  public void createRemoteDirectory(IResource resource, IProgressMonitor monitor)      throws TeamException{    try{      try{        getOpenClient().createDirectory(getRelativePath(resource).toString(),            monitor);      }      catch(SFtpException e){        if(e.getStatus().getCode()==ISFtpStatus.DOES_NOT_EXIST){          // A parent must not exist, try to create it          createRemoteDirectory(resource.getParent(), monitor);          getOpenClient().createDirectory(getRelativePath(resource).toString(),              monitor);        }        else{          throw e;        }      }    }    catch(SFtpException e){      // Some servers use 550 (DOES_NOT_EXIST) when the directory already exists.      // Therefore, don't report an error in either case. If the directory wasn't created      // another operation will fail anyway so we don't need to report it here      // P.S. The repercusions of this are that server that return 550 cannot create multiple      // ancesters for a file (i.e. upload of f1/f2/file will fail if f1 doesn't exist.      if(e.getStatus().getCode()==ISFtpStatus.DIRECTORY_EXIST          ||e.getStatus().getCode()==ISFtpStatus.DOES_NOT_EXIST)        return;      throw SFTPException.wrapException(e);    }  }  /* (non-Javadoc)   * @see org.eclipse.team.core.target.TargetDeploymentProvider#getFile(org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor)   */  public void getFile(IFile localFile, IProgressMonitor monitor)      throws TeamException{    getFile(getOpenClient(), getRelativePath(localFile).toString(), localFile,        Team.getType(localFile)!=Team.TEXT, false /* resume */, monitor);  }  /**   * Retrieves a remote file.   * @param filePath the absolute or relative path of the file   * @param localFile the local file to create   * @param binary if true, uses binary transfer type   * @param resume if true, attempts to resume a partial transfer, else overwrites   * @param monitor the progress monitor, or null   */  public void getFile(IClient client, String filePath, IFile localFile,      boolean binary, boolean resume, IProgressMonitor monitor)      throws SFTPException{    long resumeAt=0;    if(resume){      resumeAt=getFileSize(localFile);    }    InputStream in=null;    // transfer the file    try{      in=SFtpTargetResource          .getFile(client, filePath, binary, resumeAt, monitor);      if(localFile.exists()){        if(resumeAt!=0){          // don't bother remembering the previous (incomplete) generation of the file          localFile.appendContents(in, false /*force*/,              false /*keepHistory*/, null);        }        else{          localFile.setContents(in, false /*force*/, true /*keepHistory*/,              null);        }      }      else{        localFile.create(in, false /*force*/, null);      }    }    catch(CoreException e){      throw SFTPPlugin.wrapException(e);    }    finally{      if(in!=null){        try{          in.close();        }        catch(IOException e1){          // Ignore close exception        }      }    }  }  private long getFileSize(IFile file){    if(!file.exists())      return 0;    return file.getLocation().toFile().length();  }  /* (non-Javadoc)   * @see org.eclipse.team.core.target.TargetDeploymentProvider#getSynchronizer()   */  public ThreeWaySynchronizer getSynchronizer(){    return SFTPPlugin.getPlugin().getSubscriber().getSynchronizer();  }  /* (non-Javadoc)   * @see org.eclipse.team.core.target.TargetDeploymentProvider#fetchRemoteSyncBytes(org.eclipse.core.resources.IResource, org.eclipse.core.runtime.IProgressMonitor)   */  public byte[] fetchRemoteSyncBytes(IResource localResource,      IProgressMonitor monitor) throws TeamException{    throw new UnsupportedOperationException();  }  /* (non-Javadoc)   * @see org.eclipse.team.internal.target.subscriber.TargetDeploymentProvider#getSite()   */  public Site getSite(){    try{      return getSFTPSite(getUrl());    }    catch(TeamException e){      SFTPPlugin.log(e);      return null;    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -