本文整理汇总了Java中com.jcraft.jsch.SftpProgressMonitor类的典型用法代码示例。如果您正苦于以下问题:Java SftpProgressMonitor类的具体用法?Java SftpProgressMonitor怎么用?Java SftpProgressMonitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SftpProgressMonitor类属于com.jcraft.jsch包,在下文中一共展示了SftpProgressMonitor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
/**
* Send a file to server path via SFTP
* @param src
* @param path
* @throws SftpException
*/
public void put(final File src, String path) throws SftpException
{
if (!path.endsWith("/")) path = path.concat("/");
if (path.startsWith("/")) path = path.substring(1);
ChannelSftp sftp = (ChannelSftp) channel;
SftpProgressMonitor progress = new SftpProgressMonitor() {
@Override public void init(int arg0, String arg1, String arg2, long arg3)
{
System.out.println("File transfer begin..");
}
@Override public void end()
{
Out.print(LOG_LEVEL.INFO, "Upload of file "+ src.getName() +" succeeded.");
ready = true;
}
@Override public boolean count(long i) { return false; }
};
sftp.put(src.getAbsolutePath(), initRemDir+path+src.getName(), progress);
}
示例2: uploadFile
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
public void uploadFile(InputStream toBePrinted, String directory, String filename, SftpProgressMonitor progressMonitor) throws SftpException, JSchException, IOException {
if(session== null){
throw new JSchException(context.getString(R.string.misc_connection_not_set_up));
}
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp channelSftp = (ChannelSftp)channel;
try{
channelSftp.mkdir(directory);
} catch (SftpException e){
//If cannot make directory, means directory already created
}
channelSftp.cd(directory);
channelSftp.put(toBePrinted, filename, progressMonitor, ChannelSftp.OVERWRITE);
channelSftp.disconnect();
}
示例3: init
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
@Override
public void init(
int op,
String src,
String dest,
long max ) {
String operation = (op == SftpProgressMonitor.PUT)
? "UPLOAD"
: "DOWNLOAD";
log.debug("Begin " + operation + " from " + this.source + " to " + this.destination);
}
示例4: getProgressMonitor
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
/**
* Get the progress monitor.
* @return the progress monitor.
*/
protected SftpProgressMonitor getProgressMonitor() {
if (monitor == null) {
monitor = new ProgressMonitor();
}
return monitor;
}
示例5: getFile
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
private void getFile(final ChannelSftp channel,
final ChannelSftp.LsEntry le,
File localFile) throws IOException, SftpException {
final String remoteFile = le.getFilename();
if (!localFile.exists()) {
final String path = localFile.getAbsolutePath();
final int i = path.lastIndexOf(File.pathSeparator);
if (i != -1) {
if (path.length() > File.pathSeparator.length()) {
new File(path.substring(0, i)).mkdirs();
}
}
}
if (localFile.isDirectory()) {
localFile = new File(localFile, remoteFile);
}
final long startTime = System.currentTimeMillis();
final long totalLength = le.getAttrs().getSize();
SftpProgressMonitor monitor = null;
final boolean trackProgress = getVerbose() && totalLength > HUNDRED_KILOBYTES;
if (trackProgress) {
monitor = getProgressMonitor();
}
try {
log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize());
channel.get(remoteFile, localFile.getAbsolutePath(), monitor);
} finally {
final long endTime = System.currentTimeMillis();
logStats(startTime, endTime, (int) totalLength);
}
if (getPreserveLastModified()) {
FileUtils.getFileUtils().setFileLastModified(localFile,
((long) le.getAttrs()
.getMTime())
* 1000);
}
}
示例6: init
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
public void init(int op, String src, String dest, long max) {
this.max = max;
monitor = new ProgressMonitor(null,
((op == SftpProgressMonitor.PUT)
? "put" : "get") + ": " + src,
"", 0, (int) max);
count = 0;
percent = -1;
monitor.setProgress((int) this.count);
monitor.setMillisToDecideToPopup(1000);
}
示例7: init
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
@Override
public void init(int op, String src, String dest, long max) {
this.max = max;
String info = ((op == SftpProgressMonitor.PUT) ? "PUT" : "GET")
+ ": " + src + " (" + Utils.inByteFormat(max) + ")";
SFTPPD.setTitle(info);
count = 0;
percent = -1;
pb_.setMaximum((int) max);
pb_.setValue((int) this.count);
}
示例8: sendFileToRemote
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
private void sendFileToRemote(final ChannelSftp channel,
final File localFile,
String remotePath)
throws IOException, SftpException {
final long filesize = localFile.length();
if (remotePath == null) {
remotePath = localFile.getName();
}
final long startTime = System.currentTimeMillis();
final long totalLength = filesize;
// only track progress for files larger than 100kb in verbose mode
final boolean trackProgress = getVerbose() && filesize > HUNDRED_KILOBYTES;
SftpProgressMonitor monitor = null;
if (trackProgress) {
monitor = getProgressMonitor();
}
try {
if (this.getVerbose()) {
log("Sending: " + localFile.getName() + " : " + filesize);
}
channel.put(localFile.getAbsolutePath(), remotePath, monitor);
// set the fileMode on the transferred file. The "remotePath" can potentially be a directory
// into which the file got transferred, so we can't/shouldn't go ahead and try to change that directory's
// permissions. Instead we determine the path of the transferred file on remote.
final String transferredFileRemotePath;
if (channel.stat(remotePath).isDir()) {
// Note: It's correct to use "/" as the file separator without worrying about what the remote
// server's file separator is, since the SFTP spec expects "/" to be considered as file path
// separator. See section 6.2 "File Names" of the spec, which states:
// "This protocol represents file names as strings. File names are
// assumed to use the slash ('/') character as a directory separator."
transferredFileRemotePath = remotePath + "/" + localFile.getName();
} else {
transferredFileRemotePath = remotePath;
}
if (this.getVerbose()) {
log("Setting file mode '" + Integer.toOctalString(getFileMode()) + "' on remote path " + transferredFileRemotePath);
}
channel.chmod(getFileMode(), transferredFileRemotePath);
if (getPreserveLastModified()) {
// set the last modified time (seconds since epoch) on the transferred file
final int lastModifiedTime = (int) (localFile.lastModified() / 1000L);
if (this.getVerbose()) {
log("Setting last modified time on remote path " + transferredFileRemotePath + " to " + lastModifiedTime);
}
channel.setMtime(transferredFileRemotePath, lastModifiedTime);
}
} finally {
if (this.getVerbose()) {
final long endTime = System.currentTimeMillis();
logStats(startTime, endTime, (int) totalLength);
}
}
}
示例9: SftpUploadTask
import com.jcraft.jsch.SftpProgressMonitor; //导入依赖的package包/类
public SftpUploadTask(SftpProgressMonitor monitor, SftpConnection connection, IUploadNotifier callback)
{
sftpMonitor = monitor;
conn = connection;
handler = callback;
}