@Signature public Memory lstat(Environment env, String path) throws SftpException { try { SftpATTRS attrs = getWrappedObject().lstat(path); return ArrayMemory.ofNullableBean(env, attrs); } catch (SftpException e) { if ("2: No such file".equals(e.toString())) { return Memory.NULL; } throw e; } }
@Override public long getFileSize(String filePath) throws FileBasedHelperException { try { ChannelSftp channelSftp = getSftpChannel(); long fileSize = channelSftp.lstat(filePath).getSize(); channelSftp.disconnect(); return fileSize; } catch (SftpException e) { throw new FileBasedHelperException( String.format("Failed to get size for file at path %s due to error %s", filePath, e.getMessage()), e); } }
@Override public long getFileMTime(String filePath) throws FileBasedHelperException { ChannelSftp channelSftp = null; try { channelSftp = getSftpChannel(); int modificationTime = channelSftp.lstat(filePath).getMTime(); return modificationTime; } catch (SftpException e) { throw new FileBasedHelperException( String.format("Failed to get modified timestamp for file at path %s due to error %s", filePath, e.getMessage()), e); } finally { if (channelSftp != null) { channelSftp.disconnect(); } } }
@Override public boolean exists(String path) { try { this.channel.lstat(path); return true; } catch (SftpException e) { // ignore } return false; }
private boolean doTest() { try { this.channel.lstat(this.channel.getHome()); return true; } catch (Exception e) { return false; } }
@Override public boolean exists(String path) { try { this.channel.lstat(path); return true; } catch (SftpException e) { // ignore } return false; }
private boolean doTest() { try { this.channel.lstat(this.channel.getHome()); return true; } catch (Exception e) { return false; } }
public boolean fileExist(String file) { try { Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp channelSftp = (ChannelSftp) channel; channelSftp.lstat(file); return true; } catch (SftpException | JSchException e) { return false; } }
template.executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> { try { SftpATTRS file = client.lstat("foo/foobar.txt"); assertEquals(6, file.getSize());
@Override /** * @return long size * @param object file */ public long getObjectSize(ChannelSftp.LsEntry file) { long filesize = 0L; try { filesize = sftpClient.lstat(file.getFilename()).getSize(); } catch (SftpException e) { LOGGER.error("Could not lstat to get size of the file", e); } return filesize; }
SftpATTRS readAttributes(String path, boolean followLinks) throws IOException { try { return followLinks ? channel.stat(path) : channel.lstat(path); } catch (SftpException e) { throw exceptionFactory.createGetFileException(path, e); } }
private boolean accessAllowed(String path) throws SftpException, JSchException { boolean result = false; ChannelSftp channel = (ChannelSftp) session.openChannel("sftp"); SftpATTRS attrs = channel.lstat(path); result = attrs != null && ((attrs.getPermissions() & 00200) != 0) && attrs.getUId() != 0; return result; }
@Override public boolean isDirExist(String directoryPath) { try { SftpATTRS sftpATTRS = channelSftp.lstat(directoryPath); return sftpATTRS.isDir(); } catch (SftpException e) { if (e.getMessage().toLowerCase().equals("no such file")) { String message = String.format("请确认您的配置项path:[%s]存在,且配置的用户有权限读取", directoryPath); LOG.error(message); throw DataXException.asDataXException(FtpReaderErrorCode.FILE_NOT_EXISTS, message); } String message = String.format("进入目录:[%s]时发生I/O异常,请确认与ftp服务器的连接正常", directoryPath); LOG.error(message); throw DataXException.asDataXException(FtpReaderErrorCode.COMMAND_FTP_IO_EXCEPTION, message, e); } }
ChannelSftp channel = (ChannelSftp)session.openChannel("sftp"); SftpATTRS attrs = channel.lstat(fileOnServer) boolean userHasPermissionsToWriteFile = attrs != null && ((attrs.getPermissions() & 00200) != 0) && attrs.getUId() != 0;
@Override public SshFileAttributes lstat(Path path) throws SshSftpException { try { String p = PathHelper.toString(path); log.debug("lstat {}", p); SftpATTRS attrs = this.channel.lstat(p); return new JschFileAttributes(attrs); } catch (SftpException e) { throw convertSftpException(e); } }
private void retrieveDetails() throws JSchException, SftpException { if (!retrieved) { openChannel(); SftpATTRS attributes = channel.lstat(path); processAttrs(attributes); if (!keepChannelOpen) { closeChannel(); } } }
@Override public long getFileSize(String filePath) throws FileBasedHelperException { try { ChannelSftp channelSftp = getSftpChannel(); long fileSize = channelSftp.lstat(filePath).getSize(); channelSftp.disconnect(); return fileSize; } catch (SftpException e) { throw new FileBasedHelperException( String.format("Failed to get size for file at path %s due to error %s", filePath, e.getMessage()), e); } }
@Override FileStream open(final String path) throws IOException { try { final SftpATTRS a = ftp.lstat(path); return new FileStream(ftp.get(path), a.getSize()); } catch (SftpException je) { if (je.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) throw new FileNotFoundException(path); throw new TransportException(MessageFormat.format( JGitText.get().cannotGetObjectsPath, objectsPath, path, je.getMessage()), je); } }
private void setLastModified(final File localFile) throws JSchException { SftpATTRS fileAttributes = null; final ChannelSftp channel = openSftpChannel(); channel.connect(); try { fileAttributes = channel.lstat(remoteDir(remoteFile) + localFile.getName()); } catch (final SftpException e) { throw new JSchException("failed to stat remote file", e); } FileUtils.getFileUtils().setFileLastModified(localFile, ((long) fileAttributes.getMTime()) * 1000); }
@Override public boolean isLink() throws ExistsException { ChannelSftp sftp; try { sftp = alloc(); try { // CAUTION: use lstat to *not* follow links return sftp.lstat(escape(slashPath)).isLink(); } finally { free(sftp); } } catch (SftpException | JSchException e) { return noSuchFile(e); } }