I know this question sounds repeated but the difference is that i am trying to implement progress bar for Unix-Java file transfer.I am using below code for downloading the file from Unix to my local host.
String SFTPHOST = "xxx.xx.xx.xxx";
int SFTPPORT = 22;
String SFTPUSER = "abc";
String SFTPPASS = "pwd";
String SFTPWORKINGDIR = "/home/Shashank";
String SFTPDEST="G:\\xyz\\update.txt";
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
try{ JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp)channel;
channelSftp.cd(SFTPWORKINGDIR);
byte[] buffer = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(channelSftp.get("update.txt"));
File newFile = new File(SFTPDEST);
OutputStream os = new FileOutputStream(newFile);
BufferedOutputStream bos = new BufferedOutputStream(os);
int readCount;
//System.out.println("Getting: " + theLine);
while( (readCount = bis.read(buffer)) > 0) {
System.out.println("Writing: " );
bos.write(buffer, 0, readCount);
}
bis.close();
bos.close();
}catch(Exception ex){
ex.printStackTrace();
}
Please suggest me how to use progress bar in this code.I tried JSch sftp upload/download progress link but i think this isn't Java-unix file transfer.
winscpand get upload progress from it. I don't think this will work the way you expect it to. You'd better try to implement uploading/downloading your self using java library like JSch.SystemOutProgressMonitordifferently. Based on how you want to display progress to user.