本文整理汇总了Java中com.jcraft.jsch.ChannelSftp.LsEntry类的典型用法代码示例。如果您正苦于以下问题:Java LsEntry类的具体用法?Java LsEntry怎么用?Java LsEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LsEntry类属于com.jcraft.jsch.ChannelSftp包,在下文中一共展示了LsEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRemoteFileList
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Vector<LsEntry> getRemoteFileList(String user, String password, String addr, int port, String cwd) throws JSchException,
SftpException, Exception {
Session session = getSession(user, password, addr, port);
Vector<LsEntry> lsVec=null;
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
try {
lsVec=(Vector<LsEntry>)sftpChannel.ls(cwd); //sftpChannel.lpwd()
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
sftpChannel.exit();
channel.disconnect();
session.disconnect();
}
return lsVec;
}
示例2: listFiles
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
/**
* Lists directory files on remote server.
* @throws URISyntaxException
* @throws JSchException
* @throws SftpException
*/
private void listFiles() throws URISyntaxException, JSchException, SftpException {
JSch jsch = new JSch();
JSch.setLogger(new JschLogger());
setupSftpIdentity(jsch);
URI uri = new URI(sftpUrl);
Session session = jsch.getSession(sshLogin, uri.getHost(), 22);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
System.out.println("Connected to SFTP server");
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
Vector<LsEntry> directoryEntries = sftpChannel.ls(uri.getPath());
for (LsEntry file : directoryEntries) {
System.out.println(String.format("File - %s", file.getFilename()));
}
sftpChannel.exit();
session.disconnect();
}
示例3: listEntries
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
private Vector<LsEntry> listEntries(final ChannelSftp channelSftp, final String path) throws SftpException {
final Vector<LsEntry> vector = new Vector<LsEntry>();
LsEntrySelector selector = new LsEntrySelector() {
public int select(LsEntry entry) {
final String filename = entry.getFilename();
if (filename.equals(".") || filename.equals("..")) {
return CONTINUE;
}
if (entry.getAttrs().isLink()) {
vector.addElement(entry);
}
else if (entry.getAttrs().isDir()) {
if (keepDirectory(filename)) {
vector.addElement(entry);
}
}
else {
if (keepFile(filename)) {
vector.addElement(entry);
}
}
return CONTINUE;
}
};
channelSftp.ls(path, selector);
return vector;
}
示例4: ls
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public List<String> ls(String path)
throws FileBasedHelperException {
try {
List<String> list = new ArrayList<String>();
ChannelSftp channel = getSftpChannel();
Vector<LsEntry> vector = channel.ls(path);
for (LsEntry entry : vector) {
list.add(entry.getFilename());
}
channel.disconnect();
return list;
} catch (SftpException e) {
throw new FileBasedHelperException("Cannot execute ls command on sftp connection", e);
}
}
示例5: 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()));
}
示例6: ls
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
public static List<String> ls(String hostname, int port, String username, File keyFile, final String passphrase,
String path) throws JSchException, IOException, SftpException {
Session session = createSession(hostname, port, username, keyFile, passphrase);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
@SuppressWarnings("unchecked")
Vector<LsEntry> vector = (Vector<LsEntry>) channel.ls(path);
channel.disconnect();
session.disconnect();
List<String> files = new ArrayList<String>();
for (LsEntry lse : vector) {
files.add(lse.getFilename());
}
return files;
}
示例7: getFileInfo
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
@Override
public EncFSFileInfo getFileInfo(String srcPath) throws IOException {
if ("/".equals(getAbsolutePath(srcPath))) {
//return the root file info
return new EncFSFileInfo("/","/",true,0,0,true,true,true);
}
Vector<LsEntry> ls = null;
try {
String parentPath = getParentPath(getAbsolutePath(srcPath));
ls = getSession().ls(parentPath);
} catch (SftpException e){
throw new RuntimeException(e);
}
for (LsEntry lsEntry: ls){
if (lsEntry.getFilename().equals(".") || lsEntry.getFilename().equals("..")) {
continue;
}
String searchedFullPath = getAbsolutePath(srcPath);
if (searchedFullPath.endsWith("/")) searchedFullPath=searchedFullPath.substring(0,searchedFullPath.length()-1);
if (searchedFullPath.endsWith("/"+lsEntry.getFilename())) return LsEntry2EncFSFileInfo(getParentPath(getAbsolutePath(srcPath)),lsEntry);
}
return null;
}
示例8: 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;
}
示例9: _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;
}
示例10: lsEntry
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
public Vector<LsEntry> lsEntry(String path) {
Vector<LsEntry> vct = new Vector<LsEntry>();
try {
// ChannelSftp.LsEntry lsEntry = (LsEntry) v.get(i);
Vector v = sftp.ls(path);
for (Object obj : v) {
LsEntry entry = (LsEntry) obj;
if(!".".equals(entry.getFilename()) && !"..".equals(entry.getFilename())){
vct.add(entry);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
return new Vector<LsEntry>();
}
return vct;
}
示例11: ftpInboundFlow
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
@Bean
public IntegrationFlow ftpInboundFlow(SftpSinkProperties properties, SessionFactory<LsEntry> ftpSessionFactory) {
SftpMessageHandlerSpec handlerSpec =
Sftp.outboundAdapter(new SftpRemoteFileTemplate(ftpSessionFactory), properties.getMode())
.remoteDirectory(properties.getRemoteDir())
.remoteFileSeparator(properties.getRemoteFileSeparator())
.autoCreateDirectory(properties.isAutoCreateDir())
.temporaryFileSuffix(properties.getTmpFileSuffix());
if (properties.getFilenameExpression() != null) {
handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString());
}
return IntegrationFlows.from(Sink.INPUT)
.handle(handlerSpec,
new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>>>() {
@Override
public void accept(GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>> e) {
e.autoStartup(false);
}
})
.get();
}
示例12: traverse
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
/**
* Delete directory and its content recursively.
*
* @param channel
* open channel to SFTP server
* @param path
* path of the directory
* @throws SftpException
* when something went wrong
*/
@SuppressWarnings("unchecked")
private void traverse(ChannelSftp channel, String path)
throws SftpException {
SftpATTRS attrs = channel.stat(path);
if (attrs.isDir()) {
Vector<LsEntry> files = channel.ls(path);
if (files != null && files.size() > 0) {
Iterator<LsEntry> it = files.iterator();
while (it.hasNext()) {
LsEntry entry = it.next();
if ((!entry.getFilename().equals(".")) && (!entry.getFilename().equals(".."))) {
traverse(channel, path + "/" + entry.getFilename());
}
}
}
channel.rmdir(path);
} else {
channel.rm(path);
}
}
示例13: listDirectory
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Collection<File> listDirectory(String path)
throws IOException {
try {
Vector<LsEntry> files = channel.ls(path);
List<File> result = new ArrayList<File>();
if (files != null && files.size() > 0) {
Iterator<LsEntry> it = files.iterator();
while (it.hasNext()) {
LsEntry entry = it.next();
result.add(new File(path + "/" + entry.getFilename()));
}
}
return result;
} catch (SftpException e) {
if (e.id == 2) {
return Collections.emptyList();
}
logger.error("listing the directory failed.", e);
throw new IOException(e);
}
}
示例14: recursiveDelete
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
private static void recursiveDelete(ChannelSftp sftp, String path)
throws SftpException, JSchException {
Vector<?> entries = sftp.ls(path);
for (Object object : entries) {
LsEntry entry = (LsEntry) object;
if (entry.getFilename().equals(".")
|| entry.getFilename().equals("..")) {
continue;
}
if (entry.getAttrs().isDir()) {
recursiveDelete(sftp, path + entry.getFilename() + "/");
} else {
sftp.rm(path + entry.getFilename());
}
}
sftp.rmdir(path);
}
示例15: acceptListedFile
import com.jcraft.jsch.ChannelSftp.LsEntry; //导入依赖的package包/类
/**
* Filters the "." and ".." directories
*/
private boolean acceptListedFile(LsEntry file) {
if (file == null || file.getFilename() == null) {
return false;
}
String name = file.getFilename().trim().toLowerCase();
return (
! (
name.endsWith("/..")
|| name.endsWith("\\..")
|| name.endsWith("/.")
|| name.endsWith("\\.")
|| name.equals("..")
|| name.equals(".")
)
);
}