com.jcraft.jsch.ChannelSftp.get()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(1143)

本文整理了Java中com.jcraft.jsch.ChannelSftp.get()方法的一些代码示例,展示了ChannelSftp.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ChannelSftp.get()方法的具体详情如下:
包路径:com.jcraft.jsch.ChannelSftp
类名称:ChannelSftp
方法名:get

ChannelSftp.get介绍

[英]Starts downloading a file as an InputStream. This uses no progress monitor and a skip of 0.
[中]开始将文件作为InputStream下载。这不使用进度监视器,并且跳过0。

代码示例

代码示例来源:origin: looly/hutool

/**
 * 获取远程文件
 * 
 * @param src 远程文件路径
 * @param dest 目标文件路径
 * @return this
 */
public Sftp get(String src, String dest) {
  try {
    channel.get(src, dest);
  } catch (SftpException e) {
    throw new JschRuntimeException(e);
  }
  return this;
}

代码示例来源:origin: looly/hutool

/**
 * 获取远程文件
 * 
 * @param src 远程文件路径
 * @param dest 目标文件路径
 * @return this
 */
public Sftp get(String src, String dest) {
  try {
    channel.get(src, dest);
  } catch (SftpException e) {
    throw new JschRuntimeException(e);
  }
  return this;
}

代码示例来源:origin: pentaho/pentaho-kettle

/**
 * @deprecated use {@link #get(FileObject, String)}
 * @param localFilePath
 * @param remoteFile
 * @throws KettleJobException
 */
@Deprecated
public void get( String localFilePath, String remoteFile ) throws KettleJobException {
 int mode = ChannelSftp.OVERWRITE;
 try {
  c.get( remoteFile, localFilePath, null, mode );
 } catch ( SftpException e ) {
  throw new KettleJobException( e );
 }
}

代码示例来源:origin: apache/nifi

@Override
public InputStream getInputStream(final String remoteFileName, final FlowFile flowFile) throws IOException {
  final ChannelSftp sftp = getChannel(flowFile);
  try {
    return sftp.get(remoteFileName);
  } catch (final SftpException e) {
    switch (e.id) {
      case ChannelSftp.SSH_FX_NO_SUCH_FILE:
        throw new FileNotFoundException("Could not find file " + remoteFileName + " on remote SFTP Server");
      case ChannelSftp.SSH_FX_PERMISSION_DENIED:
        throw new PermissionDeniedException("Insufficient permissions to read file " + remoteFileName + " from remote SFTP Server", e);
      default:
        throw new IOException("Failed to obtain file content for " + remoteFileName, e);
    }
  }
}

代码示例来源:origin: stackoverflow.com

out= sftpChannel.get(remoteFile);
BufferedReader br = new BufferedReader(new InputStreamReader(out));
String line;

代码示例来源:origin: pentaho/pentaho-kettle

public void get( FileObject localFile, String remoteFile ) throws KettleJobException {
 OutputStream localStream = null;
 try {
  localStream = KettleVFS.getOutputStream( localFile, false );
  c.get( remoteFile, localStream );
 } catch ( SftpException e ) {
  throw new KettleJobException( e );
 } catch ( IOException e ) {
  throw new KettleJobException( e );
 } finally {
  if ( localStream != null ) {
   try {
    localStream.close();
   } catch ( IOException ignore ) {
    // Ignore any IOException, as we're trying to close the stream anyways
   }
  }
 }
}

代码示例来源:origin: stackoverflow.com

sftpChannel.get("remote-file", "local-file" );
InputStream in = sftpChannel.get( "remote-file" );

代码示例来源:origin: org.apache.hadoop/hadoop-common

@Override
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
 ChannelSftp channel = connect();
 Path workDir;
 try {
  workDir = new Path(channel.pwd());
 } catch (SftpException e) {
  throw new IOException(e);
 }
 Path absolute = makeAbsolute(workDir, f);
 FileStatus fileStat = getFileStatus(channel, absolute);
 if (fileStat.isDirectory()) {
  disconnect(channel);
  throw new IOException(String.format(E_PATH_DIR, f));
 }
 InputStream is;
 try {
  // the path could be a symbolic link, so get the real path
  absolute = new Path("/", channel.realpath(absolute.toUri().getPath()));
  is = channel.get(absolute.toUri().getPath());
 } catch (SftpException e) {
  throw new IOException(e);
 }
 FSDataInputStream fis =
   new FSDataInputStream(new SFTPInputStream(is, channel, statistics));
 return fis;
}

代码示例来源:origin: stackoverflow.com

import com.jcraft.jsch.*;

public class TestJSch {
  public static void main(String args[]) {
    JSch jsch = new JSch();
    Session session = null;
    try {
      session = jsch.getSession("username", "127.0.0.1", 22);
      session.setConfig("StrictHostKeyChecking", "no");
      session.setPassword("password");
      session.connect();

      Channel channel = session.openChannel("sftp");
      channel.connect();
      ChannelSftp sftpChannel = (ChannelSftp) channel;
      sftpChannel.get("remotefile.txt", "localfile.txt");
      sftpChannel.exit();
      session.disconnect();
    } catch (JSchException e) {
      e.printStackTrace();  
    } catch (SftpException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public InputStream get(String src, long skip, @Nullable Invoker progressMonitor) throws SftpException {
  try {
    return getWrappedObject().get(src, new SftpProgressMonitor() {
      private long max;
      private long offset;

代码示例来源:origin: apache/incubator-gobblin

/**
 * Executes a get SftpCommand and returns an input stream to the file
 * @param cmd is the command to execute
 * @param sftp is the channel to execute the command on
 * @throws SftpException
 */
@Override
public InputStream getFileStream(String file) throws FileBasedHelperException {
 SftpGetMonitor monitor = new SftpGetMonitor();
 try {
  ChannelSftp channel = getSftpChannel();
  return new SftpFsFileInputStream(channel.get(file, monitor), channel);
 } catch (SftpException e) {
  throw new FileBasedHelperException("Cannot download file " + file + " due to " + e.getMessage(), e);
 }
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
 SftpGetMonitor monitor = new SftpGetMonitor();
 try {
  ChannelSftp channelSftp = this.fsHelper.getSftpChannel();
  InputStream is = channelSftp.get(HadoopUtils.toUriPath(path), monitor);
  return new FSDataInputStream(new BufferedFSInputStream(new SftpFsHelper.SftpFsFileInputStream(is, channelSftp), bufferSize));
 } catch (SftpException e) {
  throw new IOException(e);
 }
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public InputStream readRaw(String source) throws IOException {
  try {
    return this.channel.get(source);
  }
  catch (SftpException e) {
    throw new NestedIOException("failed to read file " + source, e);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

@Override
public InputStream get(String path) throws IOException {
  return map(() -> ftp.get(path));
}

代码示例来源:origin: dadoonet/fscrawler

@Override
public InputStream getInputStream(FileAbstractModel file) throws Exception {
  return sftp.get(file.getFullpath());
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public void read(String source, OutputStream os) throws IOException {
  Assert.state(this.channel != null, "session is not connected");
  try {
    InputStream is = this.channel.get(source);
    FileCopyUtils.copy(is, os);
  }
  catch (SftpException e) {
    throw new NestedIOException("failed to read file " + source, e);
  }
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public SftpSession getSession() {
  if (this.sftpEntries.size() == 0) {
    this.init();
  }
  try {
    ChannelSftp channel = mock(ChannelSftp.class);
    String[] files = new File("remote-test-dir").list();
    for (String fileName : files) {
      when(channel.get("remote-test-dir/" + fileName))
          .thenReturn(new FileInputStream("remote-test-dir/" + fileName));
    }
    when(channel.ls("remote-test-dir")).thenReturn(sftpEntries);
    when(jschSession.openChannel("sftp")).thenReturn(channel);
    return SftpTestSessionFactory.createSftpSession(jschSession);
  }
  catch (Exception e) {
    throw new RuntimeException("Failed to create mock sftp session", e);
  }
}

代码示例来源:origin: OpenNMS/opennms

/**
 * Gets the file (from the path defined on the URL).
 *
 * @param fileName the file name
 * @return the file
 * @throws SftpException the SFTP exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public InputStream getFile(String fileName) throws SftpException, IOException {
  return getChannel().get(url.getPath() + File.separatorChar + fileName);
}

代码示例来源:origin: OpenNMS/opennms

@Override
public InputStream getInputStream() throws IOException {
  String filePath = getPath();
  try {
    return getChannel().get(filePath);
  } catch (SftpException e) {
    throw new IOException("Can't retrieve " + filePath + " from " + url.getHost() + " because " + e.getMessage());
  }
}

代码示例来源:origin: jclouds/legacy-jclouds

@Override
public Payload create() throws Exception {
  sftp = acquire(sftpConnection);
  return Payloads.newInputStreamPayload(new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp));
}

相关文章

微信公众号

最新文章

更多

ChannelSftp类方法