<p>
Gets a remote file as a <code>java.io.InputStream</code>.
</p>

@param remoteFile
remote file name
@param progress
a file transfer progress implementation.
@return ScpInputStream

@throws IOException
on any error
551918
public InputStream get(String remoteFile, FileTransferProgress progress)
			throws SshException, ChannelOpenException {

		ScpEngineIO scp = new ScpEngineIO("scp " + "-f "
		/* + (verbose ? "-v " : "") */
		+ remoteFile, ssh.openSessionChannel());
		try {
			return scp.readStreamFromRemote(remoteFile, progress);
		} catch (IOException ex) {
			scp.close();
			throw new SshException(ex, SshException.CHANNEL_FAILURE);
		}
	}
107774
public static void streamCopy(final InputStream in, final FileChannel out,
        final ProgressBar progressBar) throws IOException {
        NullArgumentException.validateNotNull(in, "Input stream");
        NullArgumentException.validateNotNull(out, "Output stream");
        final long start = System.currentTimeMillis();
        long bytes = 0;
        ProgressBar feedbackBar = progressBar;
        if (feedbackBar == null) {
            feedbackBar = new NullProgressBar();
        }
        try {
            ReadableByteChannel inChannel = Channels.newChannel(in);
            bytes = out.transferFrom(inChannel, 0, Integer.MAX_VALUE);
            inChannel.close();
        }
        finally {
            feedbackBar.increment(bytes, bytes / Math.max(System.currentTimeMillis() - start, 1));
            feedbackBar.stop();
        }
    }
756812
public static void copyFile(File srcFile, File destFile) throws IOException
    {
        InputStream reader = new FileInputStream(srcFile);
        OutputStream out = new FileOutputStream(destFile);
        try
        {
            byte[] buffer = new byte[2048];
            int n = 0;
            while (-1 != (n = reader.read(buffer))) 
            {
                out.write(buffer, 0, n);
            } 
        }
        finally
        {
            org.apache.commons.io.IOUtils.closeQuietly(out);
            org.apache.commons.io.IOUtils.closeQuietly(reader);
        }
    }
120977
public void downloadFile(String bucketName, String srcFilename, Path destFilePath)
      throws IOException {
    // [START storage_download_file]
    // The name of the bucket to access
    // String bucketName = "my-bucket";

    // The name of the remote file to download
    // String srcFilename = "file.txt";

    // The path to which the file should be downloaded
    // Path destFilePath = Paths.get("/local/path/to/file.txt");

    // Instantiate a Google Cloud Storage client
    Storage storage = StorageOptions.getDefaultInstance().getService();

    // Get specific file from specified bucket
    Blob blob = storage.get(BlobId.of(bucketName, srcFilename));

    // Download file to specified path
    blob.downloadTo(destFilePath);
    // [END storage_download_file]
  }
622522
public static long copy(InputStream in, OutputStream out, int bufferSize, StreamProgress streamProgress) throws IORuntimeException {
		Assert.notNull(in, "InputStream is null !");
		Assert.notNull(out, "OutputStream is null !");
		if (bufferSize <= 0) {
			bufferSize = DEFAULT_BUFFER_SIZE;
		}

		byte[] buffer = new byte[bufferSize];
		if (null != streamProgress) {
			streamProgress.start();
		}
		long size = 0;
		try {
			for (int readSize = -1; (readSize = in.read(buffer)) != EOF;) {
				out.write(buffer, 0, readSize);
				size += readSize;
				out.flush();
				if (null != streamProgress) {
					streamProgress.progress(size);
				}
			}
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
		if (null != streamProgress) {
			streamProgress.finish();
		}
		return size;
	}
589447
public SftpFile[] matchRemoteFiles(String remote)
			throws SftpStatusException, SshException {

		String actualDir;
		String actualSearch;
		int fileSeparatorIndex;
		if ((fileSeparatorIndex = remote.lastIndexOf("/")) > -1) {
			actualDir = remote.substring(0, fileSeparatorIndex);
			actualSearch = remote.length() > fileSeparatorIndex + 1 ? remote
					.substring(fileSeparatorIndex + 1) : "";
		} else {
			actualDir = cwd;
			actualSearch = remote;
		}

		SftpFile[] files;
		RegularExpressionMatching matcher;
		switch (RegExpSyntax) {
		case GlobSyntax:
			matcher = new GlobRegExpMatching();
			files = ls(actualDir);
			break;
		case Perl5Syntax:
			matcher = new Perl5RegExpMatching();
			files = ls(actualDir);
			break;
		default:
			matcher = new NoRegExpMatching();
			files = new SftpFile[1];
			String actual = resolveRemotePath(remote);
			files[0] = getSubsystemChannel().getFile(actual);
		}

		return matcher.matchFilesWithPattern(files, actualSearch);
	}
118570
public void get(String remoteFileName,
                    DataSink sink,
                    MarkerListener mListener)
        throws IOException, ClientException, ServerException {
        checkTransferParamsGet();

        localServer.store(sink);
        controlChannel.write(new Command("RETR", remoteFileName));

        transferRunSingleThread(localServer.getControlChannel(), mListener);
    }
1028287
protected Path downloadFileHttp(URL fileUrl) throws IOException, PluginException {
        Path destination = Files.createTempDirectory("pf4j-update-downloader");
        destination.toFile().deleteOnExit();

        String path = fileUrl.getPath();
        String fileName = path.substring(path.lastIndexOf('/') + 1);
        Path file = destination.resolve(fileName);

        // set up the URL connection
        URLConnection connection = fileUrl.openConnection();

        // connect to the remote site (may takes some time)
        connection.connect();

        // check for http authorization
        HttpURLConnection httpConnection = (HttpURLConnection) connection;
        if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
            throw new ConnectException("HTTP Authorization failure");
        }

        // try to get the server-specified last-modified date of this artifact
        long lastModified = httpConnection.getHeaderFieldDate("Last-Modified", System.currentTimeMillis());

        // try to get the input stream (three times)
        InputStream is = null;
        for (int i = 0; i < 3; i++) {
            try {
                is = connection.getInputStream();
                break;
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
        if (is == null) {
            throw new ConnectException("Can't get '" + fileUrl + " to '" + file + "'");
        }

        // reade from remote resource and write to the local file
        FileOutputStream fos = new FileOutputStream(file.toFile());
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) >= 0) {
            fos.write(buffer, 0, length);
        }
        fos.close();
        is.close();

        log.debug("Set last modified of '{}' to '{}'", file, lastModified);
        Files.setLastModifiedTime(file, FileTime.fromMillis(lastModified));

        return file;
    }
1093178
public TransferState asynchGet(String remoteFileName,
                                   DataSink sink,
                                   MarkerListener mListener)
        throws IOException, ClientException, ServerException {
        checkTransferParamsGet();

        localServer.store(sink);
        controlChannel.write(new Command("RETR", remoteFileName));

        return transferStart(localServer.getControlChannel(), mListener);
    }
1127652
public File getLocalFile(URL remoteUri)
    {
        StringBuilder sb = new StringBuilder();

        String host = remoteUri.getHost();
        String query = remoteUri.getQuery();
        String path = remoteUri.getPath();

        if (host != null)
        {
            sb.append(host);
        }
        if (path != null)
        {
            sb.append(path);
        }
        if (query != null)
        {
            sb.append('?');
            sb.append(query);
        }

        String name;

        final int maxLen = 250;

        if (sb.length() < maxLen)
        {
            name = sb.toString();
        }
        else
        {
            name = sb.substring(0, maxLen);
        }

        name = name.replace('?', '$');
        name = name.replace('*', '$');
        name = name.replace(':', '$');
        name = name.replace('<', '$');
        name = name.replace('>', '$');
        name = name.replace('"', '$');

        File f = new File(cacheDir, name);

        return f;
    }
466584
private AFTPClient actionPutFile() throws IOException, PageException {
	required("remotefile", remotefile);
	required("localfile", localfile);

	AFTPClient client = getClient();
	Resource local = ResourceUtil.toResourceExisting(pageContext, localfile);// new File(localfile);
	// if(failifexists && local.exists()) throw new ApplicationException("File ["+local+"] already
	// exist, if you want to overwrite, set attribute
	// failIfExists to false");
	InputStream is = null;

	try {
	    is = IOUtil.toBufferedInputStream(local.getInputStream());
	    client.setFileType(getType(local));
	    client.storeFile(remotefile, is);
	}
	finally {
	    IOUtil.closeEL(is);
	}
	writeCfftp(client);

	return client;
    }
453800
public String toRemote(final String host, final File localFile) {
    if (this.remoteName != null && (this.hosts == null || this.hosts.contains(host))) {
      try {
        final String canonical = localFile.getCanonicalPath();
        if (canonical.startsWith(this.canonicalPath) && isActive()) {
            return this.remoteName
                + canonical.substring(this.canonicalPath.length()).replace(File.separatorChar, this.remoteSeparator);
        }
      } catch (final IOException ex) {
        return null;
      }
    }
    return null;
  }
1117765
public static void uploadFile( Session session, String localFile, String remoteFile ) throws Exception {
        boolean ptimestamp = true;
        // exec 'scp -t rfile' remotely
        String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + remoteFile;
        Channel channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);

        // get I/O streams for remote scp
        OutputStream out = channel.getOutputStream();
        InputStream in = channel.getInputStream();

        channel.connect();

        if (checkAck(in) != 0) {
            throw new RuntimeException();
        }

        File _lfile = new File(localFile);

        if (ptimestamp) {
            command = "T " + (_lfile.lastModified() / 1000) + " 0";
            // The access time should be sent here,
            // but it is not accessible with JavaAPI ;-<
            command += (" " + (_lfile.lastModified() / 1000) + " 0\n");
            out.write(command.getBytes());
            out.flush();
            if (checkAck(in) != 0) {
                throw new RuntimeException();
            }
        }

        // send "C0644 filesize filename", where filename should not include '/'
        long filesize = _lfile.length();
        command = "C0644 " + filesize + " ";
        if (localFile.lastIndexOf('/') > 0) {
            command += localFile.substring(localFile.lastIndexOf('/') + 1);
        } else {
            command += localFile;
        }
        command += "\n";
        out.write(command.getBytes());
        out.flush();
        if (checkAck(in) != 0) {
            throw new RuntimeException();
        }

        // send a content of lfile
        FileInputStream fis = new FileInputStream(localFile);
        byte[] buf = new byte[1024];
        while( true ) {
            int len = fis.read(buf, 0, buf.length);
            if (len <= 0)
                break;
            out.write(buf, 0, len); // out.flush();
        }
        fis.close();
        fis = null;
        // send '\0'
        buf[0] = 0;
        out.write(buf, 0, 1);
        out.flush();
        if (checkAck(in) != 0) {
            throw new RuntimeException();
        }
        out.close();

        channel.disconnect();
    }
860373
public InputStream getInputStream(String pathToFile)
	throws IOException
	{
		File f = new File(pathToFile);
		return getInputStream(f);
	}
459000
public static FtpMessage get(String remotePath, DataType type) {
        return get(remotePath, FileUtils.getFileResource(remotePath).getFilename(), type);
    }
1290423
protected boolean checksumsMatch(File localFile, String remoteChecksum)
        throws IOException {
        if (remoteChecksum == null || "".equals(remoteChecksum)) {
            if (contentStream != null) {
                remoteChecksum = contentStream.getChecksum();
            } else {
                remoteChecksum = source.getSourceChecksum(contentItem);
            }
        }
        String localChecksum = getChecksum(localFile);
        return localChecksum.equals(remoteChecksum);
    }
835025
private void stream(InputStream is, File destFile) throws IOException {
        try {
            startProgress();
            OutputStream os = new FileOutputStream(destFile);
            
            boolean finished = false;
            try {
                byte[] buf = new byte[1024 * 10];
                int read;
                while ((read = is.read(buf)) >= 0) {
                    os.write(buf, 0, read);
                    processedBytes += read;
                    logProgress();
                }
                
                os.flush();
                finished = true;
            } finally {
                os.close();
                if (!finished) {
                    destFile.delete();
                }
            }
        } finally {
            is.close();
            completeProgress();
        }
    }