public void put( InputStream inputStream, String remoteFile ) throws KettleJobException { int mode = ChannelSftp.OVERWRITE; try { c.put( inputStream, remoteFile, null, mode ); } catch ( Exception e ) { throw new KettleJobException( e ); } finally { if ( inputStream != null ) { try { inputStream.close(); } catch ( IOException e ) { throw new KettleJobException( e ); } } } }
/** * 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与srcFilePath文件名相同。 * * @param srcFilePath 本地文件路径 * @param destPath 目标路径, * @param mode {@link Mode} 模式 * @return this */ public Sftp put(String srcFilePath, String destPath, Mode mode) { try { channel.put(srcFilePath, destPath, mode.ordinal()); } catch (SftpException e) { throw new JschRuntimeException(e); } return this; }
c.put(fileName, "./in/"); c.exit(); System.out.println("done");
/** * 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与srcFilePath文件名相同。 * * @param srcFilePath 本地文件路径 * @param destPath 目标路径, * @param mode {@link Mode} 模式 * @return this */ public Sftp put(String srcFilePath, String destPath, Mode mode) { try { channel.put(srcFilePath, destPath, mode.ordinal()); } catch (SftpException e) { throw new JschRuntimeException(e); } return this; }
public void put( FileObject fileObject, String remoteFile ) throws KettleJobException { int mode = ChannelSftp.OVERWRITE; InputStream inputStream = null; try { inputStream = KettleVFS.getInputStream( fileObject ); c.put( inputStream, remoteFile, null, mode ); } catch ( Exception e ) { throw new KettleJobException( e ); } finally { if ( inputStream != null ) { try { inputStream.close(); } catch ( IOException e ) { throw new KettleJobException( e ); } } } }
channelSftp.cd(SFTPWORKINGDIR); File f = new File(fileName); channelSftp.put(new FileInputStream(f), f.getName()); log.info("File transfered successfully to host."); } catch (Exception ex) {
Session session = null; Channel channel = null; try { JSch ssh = new JSch(); ssh.setKnownHosts("/path/of/known_hosts/file"); session = ssh.getSession("username", "host", 22); session.setPassword("password"); session.connect(); channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftp = (ChannelSftp) channel; sftp.put("/path/of/local/file", "/path/of/ftp/file"); } catch (JSchException e) { e.printStackTrace(); } catch (SftpException e) { e.printStackTrace(); } finally { if (channel != null) { channel.disconnect(); } if (session != null) { session.disconnect(); } }
final String previousCwd = client.pwd(); client.cd(parent.toUri().getPath()); os = client.put(f.getName()); client.cd(previousCwd); } catch (SftpException e) {
@Signature public OutputStream put(String src, Mode mode, @Nullable Invoker progressMonitor, int offset) throws SftpException { return getWrappedObject().put(src, new SftpProgressMonitor() { int op; long offset;
sftp.put(content, tempPath); } catch (final SftpException e) { throw new IOException("Unable to put content to " + fullPath + " due to " + e, e);
@Override public void append(InputStream inputStream, String destination) throws IOException { Assert.state(this.channel != null, "session is not connected"); try { this.channel.put(inputStream, destination, ChannelSftp.APPEND); } catch (SftpException e) { throw new NestedIOException("failed to write file", e); } }
@Override public void write(InputStream inputStream, String destination) throws IOException { Assert.state(this.channel != null, "session is not connected"); try { this.channel.put(inputStream, destination); } catch (SftpException e) { throw new NestedIOException("failed to write file", e); } }
@Override public OutputStream put(String path) throws IOException { return map(() -> ftp.put(path)); }
FileCopyUtils.copy((InputStream) invocation.getArgument(0), new FileOutputStream(file)); return null; }).when(channel).put(Mockito.any(InputStream.class), Mockito.anyString());
@Override public void append(InputStream inputStream, String destination) throws IOException { Assert.state(this.channel != null, "session is not connected"); try { this.channel.put(inputStream, destination, ChannelSftp.APPEND); } catch (SftpException e) { throw new NestedIOException("failed to write file", e); } }
@Override public Void create() throws Exception { sftp = acquire(sftpConnection); InputStream is = checkNotNull(contents.getInput(), "inputstream for path %s", path); try { sftp.put(is, path); } finally { Closeables.closeQuietly(contents); } return null; }
public static void uploadFile(String hostname, int port, String username, File keyFile, final String passphrase, File file, String destinationFolder) throws JSchException, IOException, SftpException { Session session = createSession(hostname, port, username, keyFile, passphrase); session.connect(); ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); channel.cd(destinationFolder); channel.put(new FileInputStream(file), file.getName()); channel.disconnect(); session.disconnect(); }
@SuppressWarnings("resource") OutputStream newOutputStream(String path, OpenOptions options) throws IOException { assert options.write; int mode = options.append ? ChannelSftp.APPEND : ChannelSftp.OVERWRITE; try { OutputStream out = channel.put(path, mode); refCount++; return new SFTPOutputStream(path, out, options.deleteOnClose); } catch (SftpException e) { throw exceptionFactory.createNewOutputStreamException(path, e, options.options); } }
@Override public Void create() throws Exception { sftp = acquire(sftpConnection); InputStream is = checkNotNull(contents.getInput(), "inputstream for path %s", path); try { sftp.put(is, path); } finally { Closeables2.closeQuietly(contents); } return null; }
public void put(String path, InputStream in, int permissions) throws SshException { try { channel.put(in, path, ChannelSftp.OVERWRITE); setPermissions(path, permissions); } catch (SftpException e) { throw new net.sf.sshapi.sftp.SftpException(e.id, e.getLocalizedMessage(), e); } }