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

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

Introduction

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

Prototype

public String getName() 

Source Link

Document

Return the name of the file.

Usage

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  .ja  va  2 s. co  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:com.connection.factory.FtpConnectionApacheLib.java

@Override
public List<RemoteFileObject> readAllFilesWalkinPath(String remotePath) {
    List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;//w  ww .j a v  a 2 s.  com
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath());
            for (FTPFile each : fileListTemp) {
                RemoteFileObject objectTemp = null;
                if (each.isDirectory()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (each.isFile()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(each.getSize());
                    objectTemp.setFileType();
                    objectTemp.setDate(each.getTimestamp().getTime());
                    willReturnObject.add(objectTemp);
                }
            }
            object = null;
            fileListTemp = null;
        }

    } catch (IOException ex) {
        return null;
    } catch (ConnectionException ex) {

    }
    return willReturnObject;
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public void readAllFilesWalkingPathWithListener(FileListener listener, String remotePath) {
    // List<RemoteFileObject> willReturnObject = new ArrayList<>();
    Queue<RemoteFileObject> directorylist = new LinkedBlockingQueue<>();
    RemoteFileObject object = null;//from  w ww.  ja  v  a 2s. c om
    object = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
    object.setDirectPath(remotePath);
    directorylist.add(object);
    try {
        while (!directorylist.isEmpty()) {
            object = directorylist.poll();
            FTPFile[] fileListTemp = _ftpObj.listFiles(object.getPath());
            for (FTPFile each : fileListTemp) {
                RemoteFileObject objectTemp = null;
                if (each.isDirectory()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.DIRECTORY);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    directorylist.add(objectTemp);
                } else if (each.isFile()) {
                    objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                    objectTemp.setFileName(each.getName());
                    objectTemp.setAbsolutePath(object.getPath());
                    objectTemp.setFileSize(each.getSize());
                    objectTemp.setFileType();
                    objectTemp.setDate(each.getTimestamp().getTime());
                    listener.handleRemoteFile(object);
                }
            }
            object = null;
            fileListTemp = null;
        }

    } catch (IOException | ConnectionException ex) {
        //    return null;
    }
    //  return willReturnObject;

    //  return willReturnObject;
}

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

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

    FTPFile parsed;

    //#215/*from   w  w w .  java  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));
}

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

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

    FTPFile parsed;

    // #1521//  w w  w . jav  a2  s.c  o m
    parsed = parser.parseFTPEntry("drwxr--r--   1 user     group          0 Feb 29 18:14 Icon\r");
    assertNotNull(parsed);
    assertEquals("Icon\r", parsed.getName());
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public List<RemoteFileObject> readAllFilesInCurrentPath(String remotePath) {
    List<RemoteFileObject> willReturnObject = new ArrayList<>();
    try {/*from   ww w.  j a  v  a2 s .c om*/
        FTPFile[] fileListTemp = _ftpObj.listFiles(remotePath);
        for (FTPFile each : fileListTemp) {
            RemoteFileObject objectTemp = null;
            if (each.isFile()) {

                objectTemp = new FtpApacheFileObject(FileInfoEnum.FILE);
                //  System.out.println(each);
                objectTemp.setFileName(each.getName());
                objectTemp.setAbsolutePath(remotePath);
                objectTemp.setFileSize(each.getSize());
                objectTemp.setFileType();
                objectTemp.setDate(each.getTimestamp().getTime());
                willReturnObject.add(objectTemp);
            }
        }
    } catch (IOException | ConnectionException ex) {
        return null;
    }
    return willReturnObject.isEmpty() ? null : willReturnObject;
}

From source file:com.claim.controller.FileTransferController.java

public void readFilesFromServer(String targetDirectory) {
    FTPClient ftpClient = new FTPClient();
    try {//from  w  w  w.  j a  va 2 s.c  om

        FtpProperties properties = new ResourcesProperties().loadFTPProperties();

        ftpClient.connect(properties.getFtp_server(), properties.getFtp_port());
        ftpClient.login(properties.getFtp_username(), properties.getFtp_password());
        ftpClient.enterLocalPassiveMode();

        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

        //FTP_REMOTE_HOME = ftpClient.printWorkingDirectory();
        FTPFile[] ftpFiles = ftpClient.listFiles();

        if (ftpFiles != null && ftpFiles.length > 0) {
            //loop thru files
            for (FTPFile file : ftpFiles) {
                if (!file.isFile()) {
                    continue;
                }
                System.out.println("File is " + file.getName());

                //get output stream
                OutputStream output;
                //output = new FileOutputStream(FTP_REMOTE_HOME + "/" + file.getName());
                output = new FileOutputStream(file.getName());
                //get the file from the remote system
                ftpClient.retrieveFile(file.getName(), output);
                //close output stream
                output.close();

                //delete the file
                //ftpClient.deleteFile(file.getName());
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (ftpClient != null) {
                ftpClient.logout();
                ftpClient.disconnect();
            }
        } catch (IOException ex) {
            Logger.getLogger(FileTransferController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:jenkins.plugins.publish_over_ftp.BapFtpClientTest.java

private FTPFile expectFtpFile(final FTPListParseEngine mockListEngine, final String filename) {
    expect(mockListEngine.hasNext()).andReturn(true);
    final FTPFile file = mockControl.createMock(FTPFile.class);
    expect(mockListEngine.getNext(1)).andReturn(new FTPFile[] { file });
    expect(file.getName()).andReturn(filename);
    return file;//from  ww w  . ja v  a2 s.com
}

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

/**
 * http://trac.cyberduck.ch/ticket/1066/*  w  w w  .java  2  s . co  m*/
 */
@Test
public void testParseNameWithBeginningWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser
            .parseFTPEntry("drw-rw-rw-   1 user      ftp             0  Mar 11 20:56  ADMIN_Documentation");
    assertNotNull(parsed);
    assertEquals(" ADMIN_Documentation", parsed.getName());
}

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

/**
 * http://trac.cyberduck.ch/ticket/1118//from w w  w .  ja v  a 2  s. com
 */
@Test
public void testParseNameWithEndingWhitespace() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser
            .parseFTPEntry("drw-rw-rw-   1 user      ftp             0  Mar 11 20:56 ADMIN_Documentation ");
    assertNotNull(parsed);
    assertEquals("ADMIN_Documentation ", parsed.getName());
}