コード例 #1
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer
  * #hardClose()
  */
 protected void hardClose() {
   try {
     if (remoteFileContents != null && scpUtil != null) {
       scpUtil.sendZeroToStream(responseStream);
       scpUtil.dispose();
       scpUtil = null;
       remoteFileContents = null;
       responseStream = null;
     }
   } catch (final IOException e) {
     exception = e;
   } finally {
     super.hardClose();
     channel = null;
     username = null;
   }
 }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ecf.provider.filetransfer.outgoing.AbstractOutgoingFileTransfer
   * #openStreams()
   */
  protected void openStreams() throws IncomingFileTransferException {
    try {
      // Set input stream from local file
      final URL url = getRemoteFileURL();
      this.username = url.getUserInfo();

      scpUtil = new ScpUtil(this);
      final Session s = scpUtil.getSession();
      s.connect();

      final String command = SCP_COMMAND + scpUtil.trimTargetFile(url.getPath());
      channel = s.openChannel(SCP_EXEC);
      ((ChannelExec) channel).setCommand(command);
      channel.connect();

      final InputStream ins = channel.getInputStream();
      responseStream = channel.getOutputStream();
      scpUtil.sendZeroToStream(responseStream);

      final int c = checkAck(ins);
      if (c != 'C') throw new IOException(Messages.ScpRetrieveFileTransfer_EXCEPTION_SCP_PROTOCOL);
      // read '0644 '
      final byte[] buf = new byte[1024];
      ins.read(buf, 0, 5);

      setFileLength(readFileSize(ins, buf));
      readFileName(ins, buf);
      // set input stream for reading rest of file
      remoteFileContents = ins;

      scpUtil.sendZeroToStream(responseStream);

      fireReceiveStartEvent();
    } catch (final Exception e) {
      channel = null;
      username = null;
      throw new IncomingFileTransferException(
          NLS.bind(
              Messages.ScpRetrieveFileTransfer_EXCEPTION_CONNECTING, getRemoteFileURL().toString()),
          e);
    }
  }
コード例 #3
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ecf.provider.filetransfer.retrieve.AbstractRetrieveFileTransfer
  * #handleReceivedData(byte[], int, double,
  * org.eclipse.core.runtime.IProgressMonitor)
  */
 protected void handleReceivedData(byte[] buf, int bytes, double factor, IProgressMonitor monitor)
     throws IOException {
   if (bytes == -1) {
     done = true;
   } else {
     int fileBytes = bytes;
     if ((bytesReceived + bytes) > fileLength) {
       fileBytes = (int) (fileLength - bytesReceived);
     }
     bytesReceived += fileBytes;
     localFileContents.write(buf, 0, fileBytes);
     fireTransferReceiveDataEvent();
     monitor.worked((int) Math.round(factor * fileBytes));
     if (fileBytes != bytes) {
       scpUtil.checkAck(buf[fileBytes], remoteFileContents);
       done = true;
     }
   }
 }