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

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

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Set the name of the file.

Usage

From source file:de.idos.updates.install.FtpInstallerTest.java

@Test
public void reportsInstallation() throws Exception {
    FTPFile ftpFile = new FTPFile();
    ftpFile.setName("name");
    ftpInstaller.installElement(ftpFile, version);
    verify(report).installingFile(ftpFile.getName());
}

From source file:de.idos.updates.store.FtpFileDataInVersionTest.java

@Test
public void addsToGivenImport() throws Exception {
    FTPFile ftpFile = new FTPFile();
    ftpFile.setName("ftpFileName");

    DataImport dataImport = mock(DataImport.class);
    when(dataImport.takeDataFromFactory(any(InputStreamFactory.class))).thenReturn(dataImport);

    FTPClient ftpClient = mock(FTPClient.class);

    new FtpFileDataInVersion(ftpClient, ftpFile, dataImport).storeIn(folder.getRoot());

    verify(dataImport).takeDataFromFactory(isA(FtpFileStreamFactory.class));
    verify(dataImport).andStoreThemIn(folder.getRoot(), "ftpFileName");
}

From source file:FileListItemAdapterTests.java

@Test
public void test() {
    adapter = new FTPListItemAdapter();
    FTPFile f = new FTPFile();
    f.setName("a");
    f.setType(FTPFile.DIRECTORY_TYPE);/*w w  w.j a v a  2 s  .c  o  m*/
    FileListItem tested = adapter.getFileListItem(f);
    Assert.assertNotNull(tested);
    Assert.assertEquals("a", tested.getLabel());
    Assert.assertEquals(FileListItemTypes.DIRECTORY, tested.getType());

}

From source file:de.idos.updates.repository.FtpRepositoryTest.java

@Test
public void createsHttpInstaller() throws Exception {
    Installation installation = mock(Installation.class);
    InstallationStrategy<FTPFile> strategy = repository.createInstallationStrategy(installation);
    Version mock = mock(Version.class);
    FTPFile ftpFile = new FTPFile();
    ftpFile.setName("X");
    strategy.installElement(ftpFile, mock);
    verify(installation).addContent(isA(FtpFileDataInVersion.class));
}

From source file:jlib.misc.MVSFTPEntryParser.java

public FTPFile parseFTPEntry(String entry) {
    FTPFile f = null;
    if (matches(entry)) {
        f = new FTPFile();
        String group = group(1);/*from   w w  w  . j  a v  a  2 s .  c o  m*/
        String dataSetName = group(2);
        f.setGroup(group);
        f.setType(FTPFile.FILE_TYPE);
        f.setName(dataSetName);

        return (f);
    }
    return null;
}

From source file:jlib.misc.MVSLibraryFTPEntryParser.java

public FTPFile parseFTPEntry(String entry) {
    FTPFile f = null;
    if (matches(entry)) {
        f = new FTPFile();
        String group = group(1);/*  w w  w . j  a v  a 2 s .  c  om*/
        String dataSetName = group;
        if (group != null && group.length() > 8)
            dataSetName = group(1).substring(0, 8).trim();
        f.setGroup(group);
        f.setType(FTPFile.FILE_TYPE);
        f.setName(dataSetName);

        return (f);
    }
    return null;
}

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

@Override
public FTPFile getFileInfo(final String path) throws IOException {
    LOGGER.debug("getFileInfo (path: {})", path);
    return executionHandler(new Callable<FTPFile>() {
        @Override//ww  w .  ja va2  s  . co m
        public FTPFile call() throws Exception {
            if ("/".equals(path)) {
                FTPFile rootFile = new FTPFile();
                rootFile.setName("/");
                rootFile.setTimestamp(GregorianCalendar.getInstance());
                return rootFile;
            } else {
                String lastPathPart = UrlUtils.getLastPathPart(path);
                String parentPath = UrlUtils.getParentPath(path);
                ftpClient.changeWorkingDirectory(parentPath);
                FTPFile[] ftpFiles = ftpClient.listFiles();
                for (FTPFile ftpFile : ftpFiles) {
                    if (ftpFile.getName().equals(lastPathPart)) {
                        return ftpFile;
                    }
                }
                return new FTPFile();
            }
        }
    });
}

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

@Override
public FTPFile parseFTPEntry(String entry) {
    FTPFile file = new FTPFile();
    file.setRawListing(entry);//from   w w  w. j  a v a 2  s  . c  om

    if (!entry.startsWith("+")) {
        return null;
    }
    int indexOfTab = entry.indexOf('\t');
    if (indexOfTab == -1) {
        return null;
    }
    // parse name.
    int startName = indexOfTab + 1;
    String name = entry.substring(startName);
    if (name.endsWith("\r\n")) {
        int i = name.lastIndexOf("\r\n");
        name = name.substring(0, i);
    }
    if (StringUtils.isBlank(name) || name.equals(".") || name.equals("..")) {
        return null;
    }
    file.setName(name);

    // parse facts.
    int i;
    int endFacts = startName - 2; // first char of name -> tab -> end of last fact.
    EPLFEntryParserContext factContext = new EPLFEntryParserContext(file);
    for (i = 1; i < endFacts; i++) {
        int factEnd = entry.indexOf(',', i);
        String fact = entry.substring(i, factEnd);
        factContext.handleFact(fact);
        i = factEnd;
    }
    factContext.conclude();

    if (!factContext.hasMayBeRetreivedFact() && !factContext.hasMayCWDToFact()) {
        return null;
    }
    return file;
}

From source file:lucee.runtime.tag.Ftp.java

private FTPFile existsFile(FTPClient client, String strPath, boolean isFile) throws PageException, IOException {
    strPath = strPath.trim();// w  w w  .  j  a v a  2  s.  c  om
    if (strPath.equals("/")) {
        FTPFile file = new FTPFile();
        file.setName("/");
        file.setType(FTPFile.DIRECTORY_TYPE);
        return file;
    }

    // get parent path
    FTPPath path = new FTPPath(client.printWorkingDirectory(), strPath);
    String p = path.getPath();
    String n = path.getName();

    strPath = p;
    if ("//".equals(p))
        strPath = "/";
    if (isFile)
        strPath += n;

    // when directory
    FTPFile[] files = null;
    try {
        files = client.listFiles(strPath);
    } catch (IOException e) {
    }

    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            if (files[i].getName().equalsIgnoreCase(n)) {
                return files[i];
            }
        }

    }
    return null;
}

From source file:com.ai.api.util.UnixFTPEntryParser.java

/**
 * Parses a line of a unix (standard) FTP server file listing and converts
 * it into a usable format in the form of an <code> FTPFile </code>
 * instance.  If the file listing line doesn't describe a file,
 * <code> null </code> is returned, otherwise a <code> FTPFile </code>
 * instance representing the files in the directory is returned.
 * <p>//ww  w . j a v a  2s  . c  o m
 * @param entry A line of text from the file listing
 * @return An FTPFile instance corresponding to the supplied entry
 */
public FTPFile parseFTPEntry(String entry) {
    FTPFile file = new FTPFile();
    file.setRawListing(entry);
    int type;
    boolean isDevice = false;

    if (matches(entry)) {
        String typeStr = group(1);
        String hardLinkCount = group(15);
        String usr = group(16);
        String grp = group(17);
        String filesize = group(18);
        String datestr = group(19) + " " + group(20);
        String name = group(21);
        String endtoken = group(22);

        try {
            //file.setTimestamp(super.parseTimestamp(datestr));
            FTPTimestampParserImplExZH Zh2En = new FTPTimestampParserImplExZH();
            file.setTimestamp(Zh2En.parseTimestamp(datestr));
        } catch (ParseException e) {
            //logger.error(e, e);
            //return null;  // this is a parsing failure too.
            //logger.info(entry+":??");
            file.setTimestamp(Calendar.getInstance());
        }

        // bcdlfmpSs-
        switch (typeStr.charAt(0)) {
        case 'd':
            type = FTPFile.DIRECTORY_TYPE;
            break;
        case 'l':
            type = FTPFile.SYMBOLIC_LINK_TYPE;
            break;
        case 'b':
        case 'c':
            isDevice = true;
            // break; - fall through
        case 'f':
        case '-':
            type = FTPFile.FILE_TYPE;
            break;
        default:
            type = FTPFile.UNKNOWN_TYPE;
        }

        file.setType(type);

        int g = 4;
        for (int access = 0; access < 3; access++, g += 4) {
            // Use != '-' to avoid having to check for suid and sticky bits
            file.setPermission(access, FTPFile.READ_PERMISSION, (!group(g).equals("-")));
            file.setPermission(access, FTPFile.WRITE_PERMISSION, (!group(g + 1).equals("-")));

            String execPerm = group(g + 2);
            if (!execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0))) {
                file.setPermission(access, FTPFile.EXECUTE_PERMISSION, true);
            } else {
                file.setPermission(access, FTPFile.EXECUTE_PERMISSION, false);
            }
        }

        if (!isDevice) {
            try {
                file.setHardLinkCount(Integer.parseInt(hardLinkCount));
            } catch (NumberFormatException e) {
                // intentionally do nothing
            }
        }

        file.setUser(usr);
        file.setGroup(grp);

        try {
            file.setSize(Long.parseLong(filesize));
        } catch (NumberFormatException e) {
            // intentionally do nothing
        }

        if (null == endtoken) {
            file.setName(name);
        } else {
            // oddball cases like symbolic links, file names
            // with spaces in them.
            name += endtoken;
            if (type == FTPFile.SYMBOLIC_LINK_TYPE) {

                int end = name.indexOf(" -> ");
                // Give up if no link indicator is present
                if (end == -1) {
                    file.setName(name);
                } else {
                    file.setName(name.substring(0, end));
                    file.setLink(name.substring(end + 4));
                }

            } else {
                file.setName(name);
            }
        }
        return file;
    } else {
        logger.info("matches(entry) failure:" + entry);
    }
    return null;
}