Example usage for org.apache.commons.net.ftp FTPFile getUser

List of usage examples for org.apache.commons.net.ftp FTPFile getUser

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPFile getUser.

Prototype

public String getUser() 

Source Link

Document

Returns the name of the user owning the file.

Usage

From source file:com.jaeksoft.searchlib.crawler.file.process.fileInstances.FtpFileInstance.java

public static List<SecurityAccess> getSecurity(FTPFile ftpFile) {
    List<SecurityAccess> accesses = new ArrayList<SecurityAccess>();
    if (ftpFile == null)
        return accesses;
    if (ftpFile.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)) {
        SecurityAccess access = new SecurityAccess();
        access.setGrant(SecurityAccess.Grant.ALLOW);
        access.setType(SecurityAccess.Type.USER);
        access.setId(ftpFile.getUser());
        accesses.add(access);//from w w  w .j av a  2 s  .  c  om
    }

    if (ftpFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)) {
        SecurityAccess access = new SecurityAccess();
        access.setGrant(SecurityAccess.Grant.ALLOW);
        access.setType(SecurityAccess.Type.GROUP);
        access.setId(ftpFile.getGroup());
        accesses.add(access);
    }

    return accesses;
}

From source file:ch.cyberduck.core.ftp.parser.HPTru64ParserTest.java

/**
 * http://trac.cyberduck.ch/ticket/2246//  w ww . ja v  a2  s . com
 */
@Test
public void testParse() throws Exception {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("drwxr-xr-x   7 ToysPKG  advertise   8192 Jun 24 11:58 Private Label Mock");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "Private Label Mock");
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("ToysPKG", parsed.getUser());
    assertEquals("advertise", parsed.getGroup());
    assertEquals(8192, parsed.getSize());
    assertEquals(Calendar.JUNE, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(24, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1 ToysPKG  advertise24809879 Jun 25 10:54 TRU-Warning Guide Master CD.sitx");
    assertNull(parsed);
}

From source file:ch.cyberduck.core.ftp.parser.NetwareFTPEntryParserTest.java

/**
 * #1996/*from  w w  w  . j a  va  2 s  . c  o  m*/
 */
@Test
public void testDateYearParser() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("- [RWCEAFMS] wtubbs 24038 May 05 17:57 CIMSscheduler_log_May02_4.txt");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "CIMSscheduler_log_May02_4.txt");
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("wtubbs", parsed.getUser());
    assertEquals(24038, parsed.getSize());
    assertEquals(Calendar.MAY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(5, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry("- [RWCEAFMS] wtubbs 9965 May 01 18:15 CIMSscheduler_log_May01.txt");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "CIMSscheduler_log_May01.txt");
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("wtubbs", parsed.getUser());
    assertEquals(9965, parsed.getSize());
    assertEquals(Calendar.MAY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}

From source file:ch.cyberduck.core.ftp.parser.FreeboxFTPEntryParserTest.java

@Test
public void testParse() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry(//from   ww  w  . j av  a  2 s  .  c  o m
            "-rw-r--r--   1  freebox  freebox 2064965868 Apr 15 21:17 M6 - Capital 15-04-2007 21h37 1h40m.ts");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "M6 - Capital 15-04-2007 21h37 1h40m.ts");
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("freebox", parsed.getUser());
    assertEquals("freebox", parsed.getGroup());
    assertEquals(2064965868, parsed.getSize());
    assertEquals(Calendar.APRIL, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1  freebox  freebox 75906880 Sep 08 06:33 Direct 8 - Gym direct - 08-09-2007 08h30 1h08m.ts");
    assertNotNull(parsed);
    assertEquals("Direct 8 - Gym direct - 08-09-2007 08h30 1h08m.ts", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("freebox", parsed.getUser());
    assertEquals("freebox", parsed.getGroup());
    assertEquals(75906880, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(8, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry(
            "-rw-r--r--   1  freebox  freebox 1171138668 May 19 17:20 France 3 national - 19-05-2007 18h15 1h05m.ts");
    assertNotNull(parsed);
    assertEquals("France 3 national - 19-05-2007 18h15 1h05m.ts", parsed.getName());
}

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

@Test
public void testParseFTPEntryExpected() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser/*from  w w  w .jav a  2s  .c  o m*/
            .parseFTPEntry("drw-rw-rw-   1 user      ftp             0  Mar 11 20:56 ADMIN_Documentation");
    assertNotNull(parsed);
    assertEquals(parsed.getType(), FTPFile.DIRECTORY_TYPE);
    assertEquals("user", parsed.getUser());
    assertEquals("ftp", parsed.getGroup());
    assertEquals("ADMIN_Documentation", parsed.getName());

    parsed = parser.parseFTPEntry("drwxr--r--   1 user     group          0 Feb 14 18:14 Downloads");
    assertNotNull(parsed);
    assertEquals("Downloads", parsed.getName());
}

From source file:at.beris.virtualfile.client.ftp.FtpFileTranslator.java

public static void fillModel(FileModel model, FTPFile ftpFile, FtpClient client) throws IOException {
    String physicalRootPath = client.getPhysicalRootPath();
    String parentPath = model.getParent() != null ? model.getParent().getUrl().getPath() : "";

    if (!"".equals(physicalRootPath)) {
        if (parentPath.length() >= physicalRootPath.length()
                && parentPath.substring(0, physicalRootPath.length()).equals(physicalRootPath))
            parentPath = "/" + parentPath.substring(physicalRootPath.length());
    }// www.jav a2s  .  com

    if (ftpFile.isSymbolicLink()) {
        String linkPath = ftpFile.getLink() + (ftpFile.getLink().endsWith("/") ? "" : "/");

        if (!"".equals(physicalRootPath)) {
            if (linkPath.length() >= physicalRootPath.length()
                    && linkPath.substring(0, physicalRootPath.length()).equals(physicalRootPath))
                linkPath = "/" + linkPath.substring(physicalRootPath.length());
        }
        String filePath = parentPath + linkPath;
        URL linkTargetUrl = UrlUtils
                .normalizeUrl(UrlUtils.newUrlReplacePath(model.getParent().getUrl(), filePath));
        model.setLinkTarget(linkTargetUrl);
    }

    model.setFileExists(true);
    model.setSize(ftpFile.getSize());
    model.setCreationTime(null);
    model.setLastModifiedTime(FileTime.fromMillis(ftpFile.getTimestamp().getTime().getTime()));
    model.setLastAccessTime(null);
    model.setAttributes(createAttributes(ftpFile));
    model.setOwner(new UnixUserPrincipal(ftpFile.getUser(), ftpFile.getGroup()));
    model.setGroup(new UnixGroupPrincipal(ftpFile.getGroup()));
    model.setDirectory(ftpFile.isDirectory());
    model.setSymbolicLink(ftpFile.isSymbolicLink());
}

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

@Test
public void testUpperCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry("drwxrwxrwx    41 spinkb  spinkb      1394 Feb 21 20:57 Desktop");
    assertNotNull(parsed);//www . j  a v a  2 s .c o m
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

@Test
public void testLowerCaseMonths() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry("drwxrwxrwx    41 spinkb  spinkb      1394 jan 21 20:57 Desktop");
    assertNotNull(parsed);//  w  w w.j a  v a2 s .  c o m
    assertEquals("Desktop", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("spinkb", parsed.getUser());
    assertEquals("spinkb", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JANUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(21, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

/**
 * http://trac.cyberduck.ch/ticket/143/*from w  w  w  .  j a va  2  s  . c  om*/
 */
@Test
public void testLeadingWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry("-rw-r--r--   1 20708    205         3553312 Feb 18 2005  D3I0_515.fmr");
    assertNotNull(parsed);
    assertTrue(parsed.isFile());
    assertEquals("D3I0_515.fmr", parsed.getName());
    assertEquals("20708", parsed.getUser());
    assertEquals("205", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.FEBRUARY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(18, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2005, parsed.getTimestamp().get(Calendar.YEAR));

    parsed = parser.parseFTPEntry("drwxr-sr-x  14 17037    209            4096 Oct  6 2000  v3r7");
    assertNotNull(parsed);
    assertTrue(parsed.isDirectory());
    assertEquals("v3r7", parsed.getName());
    assertEquals("17037", parsed.getUser());
    assertEquals("209", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2000, parsed.getTimestamp().get(Calendar.YEAR));

    // #2895
    parsed = parser.parseFTPEntry("-rwx------ 1 user group          38635 Jul 13 2006  users.xml");
    assertNotNull(parsed);
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals("users.xml", parsed.getName());
    assertEquals("user", parsed.getUser());
    assertEquals("group", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JULY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(13, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR));
}

From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java

@Test
public void testSolarisAcl() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    //#215/*  ww  w. j  a v  a  2  s. c o  m*/
    parsed = parser.parseFTPEntry("drwxrwsr-x+ 34 cristol  molvis      3072 Jul 12 20:16 molvis");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "molvis");
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals("cristol", parsed.getUser());
    assertEquals("molvis", parsed.getGroup());
    assertNotNull(parsed.getTimestamp());
    assertEquals(Calendar.JULY, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(12, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}