Java Code Examples for net.schmizz.sshj.sftp.FileAttributes#getType()
The following examples show how to use
net.schmizz.sshj.sftp.FileAttributes#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SFTPAttributesFinderFeature.java From cyberduck with GNU General Public License v3.0 | 6 votes |
public PathAttributes toAttributes(final FileAttributes stat) { final PathAttributes attributes = new PathAttributes(); switch(stat.getType()) { case REGULAR: case UNKNOWN: attributes.setSize(stat.getSize()); } if(0 != stat.getMode().getPermissionsMask()) { attributes.setPermission(new Permission(Integer.toString(stat.getMode().getPermissionsMask(), 8))); } if(0 != stat.getUID()) { attributes.setOwner(String.valueOf(stat.getUID())); } if(0 != stat.getGID()) { attributes.setGroup(String.valueOf(stat.getGID())); } if(0 != stat.getMtime()) { attributes.setModificationDate(stat.getMtime() * 1000L); } if(0 != stat.getAtime()) { attributes.setAccessedDate(stat.getAtime() * 1000L); } return attributes; }
Example 2
Source File: SFTPAttributesFinderFeature.java From cyberduck with GNU General Public License v3.0 | 5 votes |
@Override public PathAttributes find(final Path file) throws BackgroundException { if(file.isRoot()) { return PathAttributes.EMPTY; } try { final FileAttributes stat; if(file.isSymbolicLink()) { stat = session.sftp().lstat(file.getAbsolute()); } else { stat = session.sftp().stat(file.getAbsolute()); } switch(stat.getType()) { case BLOCK_SPECIAL: case CHAR_SPECIAL: case FIFO_SPECIAL: case SOCKET_SPECIAL: case REGULAR: case SYMLINK: if(!file.getType().contains(Path.Type.file)) { throw new NotfoundException(String.format("Path %s is file", file.getAbsolute())); } break; case DIRECTORY: if(!file.getType().contains(Path.Type.directory)) { throw new NotfoundException(String.format("Path %s is directory", file.getAbsolute())); } break; } return this.toAttributes(stat); } catch(IOException e) { throw new SFTPExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }