org.apache.commons.net.ftp.FTPFile Java Examples

The following examples show how to use org.apache.commons.net.ftp.FTPFile. 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: FileUtils.java    From webcurator with Apache License 2.0 7 votes vote down vote up
public static void removeFTPDirectory(FTPClient ftpClient, String directoryName) {
	try {
    	ftpClient.changeWorkingDirectory(directoryName);
    	for (FTPFile file : ftpClient.listFiles()) {
    		if (file.isDirectory()) {
    			FileUtils.removeFTPDirectory(ftpClient, file.getName());
    		} else {
        	    log.debug("Deleting " + file.getName());
    			ftpClient.deleteFile(file.getName());
    		}
    	}
    	ftpClient.changeWorkingDirectory(directoryName);
    	ftpClient.changeToParentDirectory();
	    log.debug("Deleting " + directoryName);
    	ftpClient.removeDirectory(directoryName);
	} catch (Exception ex) {
		
	}
}
 
Example #2
Source File: RumpusFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testUnknownSystIdentifier() {
    this.parser = new FTPParserSelector().getParser("Digital Domain FTP");

    FTPFile parsed;
    parsed = parser.parseFTPEntry(
        "drwxrwxrwx               folder        0 Jan 19 20:36 Mastered 1644"
    );
    assertNotNull(parsed);
    assertEquals("Mastered 1644", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());

    parsed = parser.parseFTPEntry(
        "-rwxrwxrwx        0   208143684 208143684 Jan 14 02:13 Dhannya dhannya.rar"
    );
    assertNotNull(parsed);
    assertEquals("Dhannya dhannya.rar", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());

    parsed = parser.parseFTPEntry(
        "drwxr-xr-x               folder        0 Jan 14 16:04 Probeordner");
    assertNotNull(parsed);
    assertEquals("Probeordner", parsed.getName());
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
}
 
Example #3
Source File: FTPFileSystem.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method, so that we don't open a new connection when using this
 * method from within another method. Otherwise every API invocation incurs
 * the overhead of opening/closing a TCP connection.
 */
private FileStatus[] listStatus(FTPClient client, Path file)
    throws IOException {
  Path workDir = new Path(client.printWorkingDirectory());
  Path absolute = makeAbsolute(workDir, file);
  FileStatus fileStat = getFileStatus(client, absolute);
  if (!fileStat.isDir()) {
    return new FileStatus[] { fileStat };
  }
  FTPFile[] ftpFiles = client.listFiles(absolute.toUri().getPath());
  FileStatus[] fileStats = new FileStatus[ftpFiles.length];
  for (int i = 0; i < ftpFiles.length; i++) {
    fileStats[i] = getFileStatus(ftpFiles[i], absolute);
  }
  return fileStats;
}
 
Example #4
Source File: PooledFTPOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
public FTPInfo(FTPFile file, URI parent, URI self) throws UnsupportedEncodingException {
	this.file = file;
	this.parent = parent;
	String name = file.getName();
	Matcher m = FILENAME_PATTERN.matcher(name);
	if (m.matches()) {
		name = m.group(1); // some FTPs return full file paths as names, we want only the filename 
	}
	if (name.equals("/")) {
		name = ""; // root directory has no name
	} else if (name.endsWith(URIUtils.PATH_SEPARATOR)) {
		name = name.substring(0, name.length()-1);
	}
	this.name = name;
	// name is modified just for the URI
	if (file.isDirectory() && !name.endsWith(URIUtils.PATH_SEPARATOR)) {
		name = name + URIUtils.PATH_SEPARATOR;
	}
	if (self != null) {
		this.uri = self;
	} else {
		this.uri = URIUtils.getChildURI(parent, name);
	}
}
 
Example #5
Source File: HPTru64ParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/2246
 */
@Test
public void testParse() {
    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);
}
 
Example #6
Source File: TrellixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testParse() {
    FTPFile parsed;

    //#1213
    parsed = parser.parseFTPEntry(
        "-rw-r--r--  FTP  User       10439 Apr 20 05:29 ASCheckbox_2_0.zip"
    );
    assertNotNull(parsed);
    assertEquals("ASCheckbox_2_0.zip", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(10439, parsed.getSize());
    assertEquals(Calendar.APRIL, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(20, 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));
}
 
Example #7
Source File: NetworkFile.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public NetworkFile(NetworkFile dir, FTPFile file) {
	String name = file.getName();
	String dirPath = dir.getPath();
	host = dir.host;
	this.file = file;
	if (name == null) {
		throw new NullPointerException("name == null");
	}
	if (dirPath == null || dirPath.isEmpty()) {
		this.path = fixSlashes(name);
	} else if (name.isEmpty()) {
		this.path = fixSlashes(dirPath);
	} else {
		this.path = fixSlashes(join(dirPath, name));
	}
}
 
Example #8
Source File: vsFTPdEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testParse() {
    FTPFile parsed;

    // #5437
    parsed = parser.parseFTPEntry(
        "-rw-r--r--    1 3642     3643          106 Nov 15 22:20 index.html"
    );
    assertNotNull(parsed);
    assertEquals("index.html", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(106, parsed.getSize());
    assertEquals(Calendar.NOVEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(15, 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));
}
 
Example #9
Source File: FTPOperationHandler.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
public FTPInfo(FTPFile file, URI parent, URI self) throws UnsupportedEncodingException {
	this.file = file;
	this.parent = parent;
	String name = file.getName();
	Matcher m = FILENAME_PATTERN.matcher(name);
	if (m.matches()) {
		name = m.group(1); // some FTPs return full file paths as names, we want only the filename 
	}
	this.name = name;
	if (file.isDirectory() && !name.endsWith(URIUtils.PATH_SEPARATOR)) {
		name = name + URIUtils.PATH_SEPARATOR;
	}
	if (self != null) {
		this.uri = self;
	} else {
		this.uri = URIUtils.getChildURI(parent, name);
	}
}
 
Example #10
Source File: FTPFileSystem.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method, so that we don't open a new connection when using this
 * method from within another method. Otherwise every API invocation incurs
 * the overhead of opening/closing a TCP connection.
 */
private FileStatus[] listStatus(FTPClient client, Path file)
    throws IOException {
  Path workDir = new Path(client.printWorkingDirectory());
  Path absolute = makeAbsolute(workDir, file);
  FileStatus fileStat = getFileStatus(client, absolute);
  if (fileStat.isFile()) {
    return new FileStatus[] { fileStat };
  }
  FTPFile[] ftpFiles = client.listFiles(absolute.toUri().getPath());
  FileStatus[] fileStats = new FileStatus[ftpFiles.length];
  for (int i = 0; i < ftpFiles.length; i++) {
    fileStats[i] = getFileStatus(ftpFiles[i], absolute);
  }
  return fileStats;
}
 
Example #11
Source File: FtpTransferManager.java    From desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, RemoteFile> list() throws StorageException {
    connect();

    try {
        Map<String, RemoteFile> files = new HashMap<String, RemoteFile>();
        FTPFile[] ftpFiles = ftp.listFiles(getConnection().getPath());

        for (FTPFile f : ftpFiles) {
            files.put(f.getName(), new RemoteFile(f.getName(), f.getSize(), f));
            if (f.isDirectory()) {
                files.putAll(getDirectoryList(f.getName()));
            }
        }

        return files;
    } catch (IOException ex) {
        logger.error("Unable to list FTP directory.", ex);
        throw new StorageException(ex);
    }
}
 
Example #12
Source File: NetworkStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
                                  String sortOrder) throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final NetworkFile parent = getFileForDocId(parentDocumentId);
    final NetworkConnection connection = getNetworkConnection(parentDocumentId);
    try {
        connection.getConnectedClient().changeWorkingDirectory(parent.getPath());
        for (FTPFile file : connection.getConnectedClient().listFiles()) {
            includeFile(result, null, new NetworkFile(parent, file));
        }
    } catch (IOException e) {
        Crashlytics.logException(e);
    }
    return result;
}
 
Example #13
Source File: EPLFEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
    public void testReadonlyFile() {
        FTPFile parsed = parser.parseFTPEntry("+m825718503,r,s280,\tdjb.html\r\n");

        assertEquals("djb.html", parsed.getName());
        assertFalse(parsed.isDirectory());

        assertEquals(280, parsed.getSize(), 0);

        long millis = 825718503;
        millis = millis * 1000;
        assertEquals(millis, parsed.getTimestamp().getTimeInMillis());
        assertEquals(FTPFile.FILE_TYPE, parsed.getType());
        assertFalse(parsed.isDirectory());
        assertTrue(parsed.isFile());
        assertFalse(parsed.isSymbolicLink());
//        assertEquals("owner", "Unknown", parsed.getUser());
//        assertEquals("group", "Unknown", parsed.getGroup());

//        assertEquals("permissions", "r--r--r-- (444)", parsed.attributes.getPermission().toString());
    }
 
Example #14
Source File: FtpClient.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized List<RemoteFile> listFiles() throws RemoteException {
    List<RemoteFile> result = null;
    String pwd = null;
    try {
        pwd = printWorkingDirectoryInternal();
        FTPFile[] files = ftpClient.listFiles(pwd);
        result = new ArrayList<>(files.length);
        for (FTPFile f : files) {
            // #142682
            if (f == null) {
                // hmm, really weird...
                LOGGER.log(Level.FINE, "NULL returned for listing of {0}", pwd);
                continue;
            }
            result.add(new RemoteFileImpl(f, pwd));
        }
    } catch (IOException ex) {
        WindowsJdk7WarningPanel.warn();
        LOGGER.log(Level.FINE, "Error while listing files for " + pwd, ex);
        throw new RemoteException(NbBundle.getMessage(FtpClient.class, "MSG_FtpCannotListFiles", pwd), ex, getReplyString());
    }
    scheduleKeepAlive();
    return result;
}
 
Example #15
Source File: StingrayFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/1198
 */
@Test
public void testFile() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "-r--r--r--          0     165100     165100 Aug  1 10:24 grau2.tif"
    );
    assertNotNull(parsed);
    assertEquals("grau2.tif", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE));
    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));
    assertFalse(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));
}
 
Example #16
Source File: OpensolarisFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testParse() {
    FTPFile parsed;

    // #3689
    parsed = parser.parseFTPEntry(
        "drwxr-xr-x+  5 niels    staff          7 Sep  6 13:46 data"
    );
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "data");
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(7, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}
 
Example #17
Source File: cfFTPData.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
public FTPFile[]	listFiles(String directory) {
	if ( !ftpclient.isConnected() ){
		errorText = "not connected";
		succeeded	= false;
		return null;
	}
	
	FTPFile[]	files = null;
	
	try{
		files			= ftpclient.listFiles(directory);
		errorCode = ftpclient.getReplyCode();
		succeeded	= FTPReply.isPositiveCompletion(errorCode);
	}catch(Exception e){
		errorCode = ftpclient.getReplyCode();
		errorText	= e.getMessage();
	}finally{
		setStatusData();
	}
	
	return files;
}
 
Example #18
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testStickyBit() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "drwxr--r-t   1 user     group          0 Feb 29 18:14 Filename"
    );
    assertNotNull(parsed);
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));

    parsed = parser.parseFTPEntry(
        "drwxr--r-T   1 user     group          0 Feb 29 18:14 Filename"
    );
    assertNotNull(parsed);
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}
 
Example #19
Source File: FtpExists.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {
	cfFTPData	ftpdata	= getFTPData(_session, argStruct);

	boolean soe			= getNamedBooleanParam(argStruct, "stoponerror", true);
	boolean passive	= getNamedBooleanParam(argStruct, "passive", false);
	String	file		= getNamedStringParam(argStruct, "file", "/" );

	FTPFile[]	files;
	try{
		ftpdata.lock();
		
		ftpdata.setPassive(passive);
		files = ftpdata.listFiles(file);
		if ( soe && !ftpdata.isSucceeded() )
			throwException( _session, ftpdata.getErrorText() );
		
		if ( files == null || files.length == 0 )
			return cfBooleanData.FALSE;
		else
			return cfBooleanData.TRUE;
		
	}finally{
		ftpdata.unlock();
	}
}
 
Example #20
Source File: FtpClient.java    From mumu with Apache License 2.0 6 votes vote down vote up
/** 获得目录下最大文件名 */
public String getMaxFileName(String remotePath) {
	try {
		ftpClient.changeWorkingDirectory(remotePath);
		FTPFile[] files = ftpClient.listFiles();
		Arrays.sort(files, new Comparator<FTPFile>() {
			public int compare(FTPFile o1, FTPFile o2) {
				return o2.getName().compareTo(o1.getName());
			}
		});
		return files[0].getName();
	} catch (IOException e) {
		logger.error("", e);
		throw new FtpException("FTP访问目录[" + remotePath + "]出错!", e);
	}
}
 
Example #21
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testSolarisAcl() {
    FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX");

    FTPFile parsed;

    //#215
    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));
}
 
Example #22
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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);
    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));
}
 
Example #23
Source File: FtpFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Called by child file objects, to locate their ftp file info.
 *
 * @param name the file name in its native form ie. without URI stuff (%nn)
 * @param flush recreate children cache
 */
private FTPFile getChildFile(final String name, final boolean flush) throws IOException {
    /*
     * If we should flush cached children, clear our children map unless we're in the middle of a refresh in which
     * case we've just recently refreshed our children. No need to do it again when our children are refresh()ed,
     * calling getChildFile() for themselves from within getInfo(). See getChildren().
     */
    if (flush && !inRefresh.get()) {
        children = null;
    }

    // List the children of this file
    doGetChildren();

    // Look for the requested child
    // VFS-210 adds the null check.
    return children != null ? children.get(name) : null;
}
 
Example #24
Source File: FTPFileSystem.java    From RDFS with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the file information in FTPFile to a {@link FileStatus} object. *
 * 
 * @param ftpFile
 * @param parentPath
 * @return FileStatus
 */
private FileStatus getFileStatus(FTPFile ftpFile, Path parentPath) {
  long length = ftpFile.getSize();
  boolean isDir = ftpFile.isDirectory();
  int blockReplication = 1;
  // Using default block size since there is no way in FTP client to know of
  // block sizes on server. The assumption could be less than ideal.
  long blockSize = DEFAULT_BLOCK_SIZE;
  long modTime = ftpFile.getTimestamp().getTimeInMillis();
  long accessTime = 0;
  FsPermission permission = getPermissions(ftpFile);
  String user = ftpFile.getUser();
  String group = ftpFile.getGroup();
  Path filePath = new Path(parentPath, ftpFile.getName());
  return new FileStatus(length, isDir, blockReplication, blockSize, modTime,
      accessTime, permission, user, group, filePath.makeQualified(this));
}
 
Example #25
Source File: FtpSinkConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Bean
public IntegrationFlow ftpInboundFlow(FtpSinkProperties properties, SessionFactory<FTPFile> ftpSessionFactory) {
	FtpMessageHandlerSpec handlerSpec =
		Ftp.outboundAdapter(new FtpRemoteFileTemplate(ftpSessionFactory), properties.getMode())
			.remoteDirectory(properties.getRemoteDir())
			.remoteFileSeparator(properties.getRemoteFileSeparator())
			.autoCreateDirectory(properties.isAutoCreateDir())
			.temporaryFileSuffix(properties.getTmpFileSuffix());
	if (properties.getFilenameExpression() != null) {
		handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString());
	}
	return IntegrationFlows.from(Sink.INPUT)
		.handle(handlerSpec,
			new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>>>() {
				@Override
				public void accept(GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>> e) {
					e.autoStartup(false);
				}
			})
		.get();
}
 
Example #26
Source File: FtpFileObject.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Lists the children of the file.
 */
@Override
protected String[] doListChildren() throws Exception {
    // List the children of this file
    doGetChildren();

    // VFS-210
    if (children == null) {
        return null;
    }

    // TODO - get rid of this children stuff
    final String[] childNames = new String[children.size()];
    int childNum = -1;
    final Iterator<FTPFile> iterChildren = children.values().iterator();
    while (iterChildren.hasNext()) {
        childNum++;
        final FTPFile child = iterChildren.next();
        childNames[childNum] = child.getName();
    }

    return UriParser.encode(childNames);
}
 
Example #27
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/1066
 */
@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());
}
 
Example #28
Source File: UnixFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
/**
 * http://trac.cyberduck.ch/ticket/1118
 */
@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());
}
 
Example #29
Source File: AXSPortFTPEntryParserTest.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testParseDirectory() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry(
        "d--------   1 owner    group               0 Dec 22 10:19 DATALOGS");
    assertNull(parsed);
}
 
Example #30
Source File: FtpFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Fetches the children of this file, if not already cached.
 */
private void doGetChildren() throws IOException {
    if (children != null) {
        return;
    }

    final FtpClient client = getAbstractFileSystem().getClient();
    try {
        final String path = fileInfo != null && fileInfo.isSymbolicLink()
                ? getFileSystem().getFileSystemManager().resolveName(getParent().getName(), fileInfo.getLink())
                        .getPath()
                : relPath;
        final FTPFile[] tmpChildren = client.listFiles(path);
        if (tmpChildren == null || tmpChildren.length == 0) {
            children = EMPTY_FTP_FILE_MAP;
        } else {
            children = new TreeMap<>();

            // Remove '.' and '..' elements
            for (int i = 0; i < tmpChildren.length; i++) {
                final FTPFile child = tmpChildren[i];
                if (child == null) {
                    if (log.isDebugEnabled()) {
                        log.debug(Messages.getString("vfs.provider.ftp/invalid-directory-entry.debug",
                                Integer.valueOf(i), relPath));
                    }
                    continue;
                }
                if (!".".equals(child.getName()) && !"..".equals(child.getName())) {
                    children.put(child.getName(), child);
                }
            }
        }
    } finally {
        getAbstractFileSystem().putClient(client);
    }
}