當前位置: 首頁>>代碼示例>>Java>>正文


Java SftpATTRS類代碼示例

本文整理匯總了Java中com.jcraft.jsch.SftpATTRS的典型用法代碼示例。如果您正苦於以下問題:Java SftpATTRS類的具體用法?Java SftpATTRS怎麽用?Java SftpATTRS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SftpATTRS類屬於com.jcraft.jsch包,在下文中一共展示了SftpATTRS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exists

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
@Override
public boolean exists() {
    Channel channel = null;
    try {
        channel = SFTPSession.getInstance().getSFTPChannel(mUri);
        SftpATTRS attrs =  ((ChannelSftp)channel).stat(mUri.getPath());
        channel.disconnect();
        return attrs !=null;
    } catch (Exception e) {
        if(channel!=null&&channel.isConnected())
            channel.disconnect();
        e.printStackTrace();
    }finally {
        if(channel!=null&&channel.isConnected())
            channel.disconnect();
    }
    return false;
}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:19,代碼來源:SftpFileEditor.java

示例2: createStatInfo

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
private StatInfo createStatInfo(String dirName, String baseName, SftpATTRS attrs, ChannelSftp cftp) throws SftpException {
    String linkTarget = null;
    if (attrs.isLink()) {
        String path = dirName + '/' + baseName;
        RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("readlink", path); // NOI18N
        try {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "performing readlink {0}", path);
            }
            linkTarget = cftp.readlink(path);
        } finally {
            RemoteStatistics.stopChannelActivity(activityID);
        }
    }
    Date lastModified = new Date(attrs.getMTime() * 1000L);
    StatInfo result = new FileInfoProvider.StatInfo(baseName, attrs.getUId(), attrs.getGId(), attrs.getSize(),
            attrs.isDir(), attrs.isLink(), linkTarget, attrs.getPermissions(), lastModified);
    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:SftpSupport.java

示例3: SFTPFile2

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
public SFTPFile2(SftpATTRS stat, String filename, Uri uri) {
    if (filename == null){
        throw new IllegalArgumentException("filename cannot be null");
    }
    if (uri == null) {
        throw new IllegalArgumentException("uri cannot be null");
    }

    mUriString = uri.toString();
    mName = filename;
    mIsDirectory = stat.isDir();
    mIsFile = !stat.isDir();
    mLastModified = stat.getMTime();
    //TODO : permissions
    mCanRead = true;
    mCanWrite = true;
    mLength = stat.getSize();
}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:19,代碼來源:SFTPFile2.java

示例4: getFileEntry

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
@Override
public FileEntry getFileEntry(String filename) throws Exception {

	ChannelSftp c = init(filename);
	try {
		FileEntry fileEntry = new FileEntry();
		String sessionPath = extractSessionPath(filename);
		SftpATTRS attr = c.stat(sessionPath);
		setFromAttrs(fileEntry, attr);
		fileEntry.path = filename;
		fileEntry.displayName = getFilename(sessionPath);
		tryDisconnect(c);
		return fileEntry;
	} catch (Exception e) {
		logDebug("Exception in getFileEntry! " + e);
		tryDisconnect(c);
		throw convertException(e);
	}
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:20,代碼來源:SftpStorage.java

示例5: getFileStatus

import com.jcraft.jsch.SftpATTRS; //導入依賴的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()));
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:47,代碼來源:SFTPFileSystem.java

示例6: LsEntry2EncFSFileInfo

import com.jcraft.jsch.SftpATTRS; //導入依賴的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;
}
 
開發者ID:starn,項目名稱:encdroidMC,代碼行數:23,代碼來源:FileProvider6.java

示例7: exists

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
public boolean exists(String filename) throws FileSystemException {
    // we have to be connected
    if (channel == null) {
        throw new FileSystemException("Not yet connected to SFTP server");
    }

    // easiest way to check if a file already exists is to do a file stat
    // this method will error out if the remote file does not exist!
    try {
        SftpATTRS attrs = channel.stat(filename);
        // if we get here, then file exists
        return true;
    } catch (SftpException e) {
        // map "no file" message to return correct result
        if (e.getMessage().toLowerCase().indexOf("no such file") >= 0) {
            return false;
        }
        // otherwise, this means an underlying error occurred
        throw new FileSystemException("Underlying error with SFTP session while checking if file exists", e);
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:22,代碼來源:SftpRemoteFileSystem.java

示例8: _buildFiles

import com.jcraft.jsch.SftpATTRS; //導入依賴的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;  
}
 
開發者ID:xnx3,項目名稱:xnx3,代碼行數:26,代碼來源:SFTPUtil.java

示例9: existsDirectory

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
/**
     * Determines whether a directory exists or not
     * 如果是文件,也會拋出異常,返回 false
     *
     * @param remoteDirectoryPath
     * @return true if exists, false otherwise
     * @throws IOException thrown if any I/O error occurred.
     */
    @Override
    public boolean existsDirectory(String remoteDirectoryPath) {

        try {
            // System.out.println(channel.realpath(remoteFilePath));
            SftpATTRS attrs = channel.stat(remoteDirectoryPath);
            return attrs.isDir();
        } catch (SftpException e) {
            // e.printStackTrace();
            return false;
        }


//        String originalWorkingDirectory = getWorkingDirectory();
//        try {
//            changeDirectory(remoteDirectoryPath);
//        } catch (FtpException e) {
//            //文件夾不存在,會拋出異常。
//            return false;
//        }
//        //恢複 ftpClient 當前工作目錄屬性
//        changeDirectory(originalWorkingDirectory);
//        return true;
    }
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:33,代碼來源:SftpConnection.java

示例10: setUp

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    classpathService = new ClasspathService(project);
    hostFiles = Arrays.asList(jar1, jar2, output);
    when(jar1.getName()).thenReturn(JAR1_NAME);
    when(jar1.lastModified()).thenReturn(JAR1_LAST_MODIFIED);
    when(jar1.length()).thenReturn(JAR1_SIZE);
    when(jar2.getName()).thenReturn(JAR2_NAME);
    when(jar2.length()).thenReturn(JAR2_SIZE);
    when(jar2.lastModified()).thenReturn(JAR2_LAST_MODIFIED);
    when(output.getName()).thenReturn("untitledproject");
    when(jar1Server.getFilename()).thenReturn(JAR1_NAME);
    when(jar2Server.getFilename()).thenReturn(JAR2_NAME);
    when(jar1Server.getAttrs()).thenReturn(mock(SftpATTRS.class));
    when(jar2Server.getAttrs()).thenReturn(mock(SftpATTRS.class));
    Vector vector = new Vector();
    vector.add(jar1Server);
    vector.add(jar2Server);
    when(target.getAlreadyDeployedLibraries()).thenReturn(vector);
}
 
開發者ID:asebak,項目名稱:embeddedlinux-jvmdebugger-intellij,代碼行數:21,代碼來源:ClasspathServiceTest.java

示例11: traverse

import com.jcraft.jsch.SftpATTRS; //導入依賴的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);
    }
}
 
開發者ID:psnc-dl,項目名稱:darceo,代碼行數:31,代碼來源:SftpDataStorageClient.java

示例12: put

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
@Override
public void put(FileAttrs file, InputStream in) throws Throwable {
    String path = file.path();
    if (file.isDirectory()) {
        mkdirs(this.channel, path, preserve() ? file.mode() : null, preserve() ? file.mtime() : null);
    } else {
        String parent = PathUtils.getParent(path);
        if (parent != null && !exists(this.channel, parent)) {
            mkdirs(this.channel, parent, null, null);
        }
        this.channel.put(in, path, null, com.jcraft.jsch.ChannelSftp.OVERWRITE);
        if (preserve()) {
            // TODO test
            SftpATTRS attrs = this.channel.stat(path);
            attrs.setPERMISSIONS(file.mode());
            attrs.setACMODTIME(file.atime(), file.mtime());
            this.channel.setStat(path, attrs);
        }
    }
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:21,代碼來源:JschSftpClient.java

示例13: resolveResource

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
/**
 * This method is similar to getResource, except that the returned resource is fully initialized
 * (resolved in the sftp repository), and that the given string is a full remote path
 *
 * @param path
 *            the full remote path in the repository of the resource
 * @return a fully initialized resource, able to answer to all its methods without needing any
 *         further connection
 */
@SuppressWarnings("unchecked")
public Resource resolveResource(String path) {
    try {
        List<LsEntry> r = getSftpChannel(path).ls(getPath(path));
        if (r != null) {
            SftpATTRS attrs = r.get(0).getAttrs();
            return new BasicResource(path, true, attrs.getSize(),
                        attrs.getMTime() * MILLIS_PER_SECOND, false);
        }
    } catch (Exception e) {
        Message.debug("Error while resolving resource " + path, e);
        // silent fail, return nonexistent resource
    }

    return new BasicResource(path, false, 0, 0, false);
}
 
開發者ID:apache,項目名稱:ant-ivy,代碼行數:26,代碼來源:SFTPRepository.java

示例14: execute

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
@Override
protected void execute() throws SftpResult, JSchException {
    ChannelSftp ch = channel();
    try {
        SftpATTRS attrs = ch.stat(path);
        throw new SftpResult(attrs);
    } catch (SftpException e) {
        if (e.id == SSH_FX_NO_SUCH_FILE) {
            throw new SftpResult(null);
        } else {
            throw new SftpError(e, "Error checking stat of %s", path);
        }
    } finally {
        release(ch);
    }
}
 
開發者ID:osglworks,項目名稱:java-sftp,代碼行數:17,代碼來源:Stat.java

示例15: getFileType

import com.jcraft.jsch.SftpATTRS; //導入依賴的package包/類
public FileType getFileType(String filename) throws KettleJobException
 {
try {
	SftpATTRS attrs=c.stat(filename);
		if (attrs == null)	return FileType.IMAGINARY;
		
		if ((attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS) == 0)
			throw new KettleJobException("Unknown permissions error");

		if (attrs.isDir())
			return FileType.FOLDER;
		else
			return FileType.FILE;
} catch (Exception e) {
		throw new KettleJobException(e);
	}
}
 
開發者ID:icholy,項目名稱:geokettle-2.0,代碼行數:18,代碼來源:SFTPClient.java


注:本文中的com.jcraft.jsch.SftpATTRS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。