本文整理匯總了Java中com.jcraft.jsch.ChannelSftp.LsEntry.getAttrs方法的典型用法代碼示例。如果您正苦於以下問題:Java LsEntry.getAttrs方法的具體用法?Java LsEntry.getAttrs怎麽用?Java LsEntry.getAttrs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jcraft.jsch.ChannelSftp.LsEntry
的用法示例。
在下文中一共展示了LsEntry.getAttrs方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFileStatus
import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
/**
* Convert the file information in LsEntry to a {@link FileStatus} object. *
*
* @param sftpFile
* @param parentPath
* @return file status
* @throws IOException
*/
private FileStatus getFileStatus(ChannelSftp channel, LsEntry sftpFile,
Path parentPath) throws IOException {
SftpATTRS attr = sftpFile.getAttrs();
long length = attr.getSize();
boolean isDir = attr.isDir();
boolean isLink = attr.isLink();
if (isLink) {
String link = parentPath.toUri().getPath() + "/" + sftpFile.getFilename();
try {
link = channel.realpath(link);
Path linkParent = new Path("/", link);
FileStatus fstat = getFileStatus(channel, linkParent);
isDir = fstat.isDirectory();
length = fstat.getLen();
} catch (Exception e) {
throw new IOException(e);
}
}
int blockReplication = 1;
// Using default block size since there is no way in SFTP channel to know of
// block sizes on server. The assumption could be less than ideal.
long blockSize = DEFAULT_BLOCK_SIZE;
long modTime = attr.getMTime() * 1000; // convert to milliseconds
long accessTime = 0;
FsPermission permission = getPermissions(sftpFile);
// not be able to get the real user group name, just use the user and group
// id
String user = Integer.toString(attr.getUId());
String group = Integer.toString(attr.getGId());
Path filePath = new Path(parentPath, sftpFile.getFilename());
return new FileStatus(length, isDir, blockReplication, blockSize, modTime,
accessTime, permission, user, group, filePath.makeQualified(
this.getUri(), this.getWorkingDirectory()));
}
示例2: LsEntry2EncFSFileInfo
import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private EncFSFileInfo LsEntry2EncFSFileInfo(String parentPath, LsEntry file){
EncFSFileInfo result;
try {
String name = file.getFilename();
SftpATTRS attrs = file.getAttrs();
long mtime = attrs.getMTime();
boolean isDir = attrs.isDir();
long length = attrs.getSize();
String relativePath=this.getRelativePathFromAbsolutePath(parentPath);
if (name.endsWith("/")) name=name.substring(0,name.length()-1);
result = new EncFSFileInfo(name,relativePath,isDir,mtime,length,true,true,true);
} catch (Exception e){
throw new RuntimeException(e);
}
return result;
}
示例3: _buildFiles
import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private List<FileBean> _buildFiles(Vector ls,String dir) throws Exception {
if (ls != null && ls.size() >= 0) {
List<FileBean> list = new ArrayList<FileBean>();
for (int i = 0; i < ls.size(); i++) {
LsEntry f = (LsEntry) ls.get(i);
String nm = f.getFilename();
if (nm.equals(".") || nm.equals(".."))
continue;
SftpATTRS attr = f.getAttrs();
FileBean fileBean=new FileBean();
if (attr.isDir()) {
fileBean.setDir(true);
} else {
fileBean.setDir(false);
}
fileBean.setAttrs(attr);
fileBean.setFilePath(dir);
fileBean.setFileName(nm);
list.add(fileBean);
}
return list;
}
return null;
}
示例4: listFiles
import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private List<FileEntry> listFiles(String path, ChannelSftp c) throws Exception {
try {
List<FileEntry> res = new ArrayList<FileEntry>();
@SuppressWarnings("rawtypes")
java.util.Vector vv = c.ls(extractSessionPath(path));
if (vv != null) {
for (int ii = 0; ii < vv.size(); ii++) {
Object obj = vv.elementAt(ii);
if (obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry) {
LsEntry lsEntry = (com.jcraft.jsch.ChannelSftp.LsEntry) obj;
if ((lsEntry.getFilename().equals("."))
||(lsEntry.getFilename().equals(".."))
)
continue;
FileEntry fileEntry = new FileEntry();
fileEntry.displayName = lsEntry.getFilename();
fileEntry.path = createFilePath(path, fileEntry.displayName);
SftpATTRS attrs = lsEntry.getAttrs();
setFromAttrs(fileEntry, attrs);
res.add(fileEntry);
}
}
}
return res;
} catch (Exception e) {
tryDisconnect(c);
throw convertException(e);
}
}
示例5: call
import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public StatInfo[] call() throws IOException, CancellationException, JSchException, ExecutionException, InterruptedException, SftpException {
if (!path.startsWith("/")) { //NOI18N
throw new FileNotFoundException("Path is not absolute: " + path); //NOI18N
}
List<StatInfo> result = null;
SftpException exception = null;
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "{0} started", getTraceName());
}
String threadName = Thread.currentThread().getName();
Thread.currentThread().setName(PREFIX + ": " + getTraceName()); // NOI18N
int attempt = 1;
try {
for (; attempt <= LS_RETRY_COUNT; attempt++) {
ChannelSftp cftp = getChannel();
RemoteStatistics.ActivityID lsLoadID = RemoteStatistics.startChannelActivity("lsload", path); // NOI18N
try {
List<LsEntry> entries = (List<LsEntry>) cftp.ls(path);
result = new ArrayList<>(Math.max(1, entries.size() - 2));
for (LsEntry entry : entries) {
String name = entry.getFilename();
if (!".".equals(name) && !"..".equals(name)) { //NOI18N
SftpATTRS attrs = entry.getAttrs();
//if (!(attrs.isDir() || attrs.isLink())) {
// if ( (attrs.getPermissions() & S_IFMT) != S_IFREG) {
// // skip not regular files
// continue;
// }
//}
result.add(createStatInfo(path, name, attrs, cftp));
}
}
exception = null;
break;
} catch (SftpException e) {
exception = e;
if (e.id == SftpIOException.SSH_FX_FAILURE) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "{0} - exception while attempt {1}", new Object[]{getTraceName(), attempt});
}
if (MiscUtils.mightBrokeSftpChannel(e)) {
cftp.quit();
}
} else {
// re-try in case of failure only
// otherwise consider this exception as unrecoverable
break;
}
} finally {
RemoteStatistics.stopChannelActivity(lsLoadID);
releaseChannel(cftp);
}
}
} finally {
Thread.currentThread().setName(threadName);
}
if (exception != null) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "{0} failed", getTraceName());
}
throw decorateSftpException(exception, path);
}
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "{0} finished in {1} attempt(s)", new Object[]{getTraceName(), attempt});
}
return result == null ? new StatInfo[0] : result.toArray(new StatInfo[result.size()]);
}
示例6: listFiles
import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
public List<SshFile> listFiles(String path) {
path = getAbsolutePath(path);
try {
Vector vector = getSftpChannel().ls(path);
if (vector == null || vector.isEmpty()) {
return Collections.EMPTY_LIST;
}
List<SshFile> sshFiles = new ArrayList<>(vector.size());
for (Iterator<LsEntry> iter = vector.iterator(); iter.hasNext(); ) {
LsEntry entry = iter.next();
String filename = entry.getFilename();
if (filename.equals(".") || filename.equals("..")) {
continue;
}
SftpATTRS attr = entry.getAttrs();
SshFile file = new SshFile();
file.setName(entry.getFilename());
String filePath = createPath(path, entry.getFilename());
file.setPath(getAbsolutePath(filePath));
file.setLength(attr.getSize());
FilePermission permission = new FilePermission(attr.getPermissions());
file.setPermission(permission);
FileType t = FileType.parse(attr.getPermissions() & FileType.S_IFMT);
file.setType(t);
List<String> tokens = splitStringAndOmitEmpty(entry.getLongname(), " ");
String owner = tokens.get(2);
String group = tokens.get(3);
file.setOwner(owner);
file.setGroup(group);
file.setLastAccessTime(new Date(((long) attr.getATime()) * 1000L));
file.setLastModifiedTime(new Date(((long) attr.getMTime()) * 1000L));
sshFiles.add(file);
}
return sshFiles;
} catch (Exception e) {
if (e instanceof SshException) {
throw (SshException) e;
}
throw new SshException(e);
}
}