package com.zehon.sftp.samples;
/**
* This DownloadFileAsStreamSample
class
* This sample demonstrates how to download a file via SFTP, the result is a java.io.InputStream
* This sample uses a convenient method, for a Spring-able version of this refer to FTPsClient
* @see com.zehon.ftp.FTPsClient
* Please refer to http://www.zehon.com/features.htm for more information about our SFTP.
* @author Zehon Team (we're happy to serve you!) http://www.zehon.com/
*
*/
import java.io.IOException;
import java.io.InputStream;
import com.zehon.sftp.SFTP;
public class DownloadFileAsStreamSample {
/**
* Please refer to http://www.zehon.com/SFTP_samples.htm for its full source code
* @param args
*/
public static void main(String[] args) {
String host = "sftp.zehon.com";
String username = "sftp";
String password = "sftp";
String nameOfFile = "testStream.txt";
InputStream is = null;
String remoteFolder = "/test";
try {
is = SFTP.getFileAsStream(nameOfFile, remoteFolder, host, username, password);
System.out.println("Download the file with size "+is.available());
is.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}