Android Open Source - prim-ftpd Android File System View






From Project

Back to project page prim-ftpd.

License

The source code is released under:

Apache License

If you think the Android project prim-ftpd listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.primftpd.filesystem;
//from w w  w . j a  v a2 s.  c o  m
import java.io.File;

import org.apache.ftpserver.ftplet.FileSystemView;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.FtpFile;
import org.apache.ftpserver.ftplet.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AndroidFileSystemView implements FileSystemView {

  private static final Logger logger = LoggerFactory.getLogger(AndroidFileSystemView.class);

  private final User user;

  private AndroidFtpFile workingDir;

  public AndroidFileSystemView(User user) {
    this.user = user;
    workingDir = createHomeDirObj(user);
  }

  private AndroidFtpFile createHomeDirObj(User user) {
    return new AndroidFtpFile(new File(user.getHomeDirectory()), user);
  }

  @Override
  public FtpFile getHomeDirectory() throws FtpException {
    logger.debug("getHomeDirectory()");
    return createHomeDirObj(user);
  }

  @Override
  public FtpFile getWorkingDirectory() throws FtpException {
    logger.debug("getWorkingDirectory()");

    return workingDir;
  }

  @Override
  public boolean changeWorkingDirectory(String dir) throws FtpException {
    logger.debug("changeWorkingDirectory({})", dir);

    File dirObj = new File(dir);

    if (dirObj.isFile()) {
      return false;
    }

    String path = dir;
    if (!dirObj.isAbsolute()) {
      path = workingDir.getAbsolutePath() + File.separator + dir;
    }

    workingDir = new AndroidFtpFile(new File(path), user);

    return true;
  }

  @Override
  public FtpFile getFile(String file) throws FtpException {
    logger.debug("getFile({})", file);

    File fileObj = new File(file);
    if (fileObj.isAbsolute()) {
      logger.debug("getFile(), returning abs: '{}'", file);
      return new AndroidFtpFile(fileObj, user);
    }

    // handle relative paths
    file = workingDir.getAbsolutePath() + File.separator + file;

    logger.debug("getFile(), returning rel: '{}'", file);

    return new AndroidFtpFile(new File(file), user);
  }

  @Override
  public boolean isRandomAccessible() throws FtpException {
    logger.debug("isRandomAccessible()");
    return true;
  }

  @Override
  public void dispose() {
    logger.debug("dispose()");
  }

}




Java Source Code List

org.primftpd.AndroidPrefsUserManager.java
org.primftpd.EncryptingEditTextPreference.java
org.primftpd.FtpPrefsActivity.java
org.primftpd.FtpPrefsFragment.java
org.primftpd.FtpServerService.java
org.primftpd.NotificationUtil.java
org.primftpd.PrefsBean.java
org.primftpd.PrimitiveFtpdActivity.java
org.primftpd.filesystem.AndroidFileSystemFactory.java
org.primftpd.filesystem.AndroidFileSystemView.java
org.primftpd.filesystem.AndroidFtpFile.java
org.primftpd.util.EncryptionUtil.java
org.primftpd.util.KeyStoreUtil.java
org.primftpd.util.StringUtils.java
org.slf4j.ILoggerFactory.java
org.slf4j.IMarkerFactory.java
org.slf4j.LoggerFactory.java
org.slf4j.Logger.java
org.slf4j.MDC.java
org.slf4j.MarkerFactory.java
org.slf4j.Marker.java
org.slf4j.helpers.BasicMDCAdapter.java
org.slf4j.helpers.BasicMarkerFactory.java
org.slf4j.helpers.BasicMarker.java
org.slf4j.helpers.FormattingTuple.java
org.slf4j.helpers.MarkerIgnoringBase.java
org.slf4j.helpers.MessageFormatter.java
org.slf4j.helpers.NOPLoggerFactory.java
org.slf4j.helpers.NOPLogger.java
org.slf4j.helpers.NOPMDCAdapter.java
org.slf4j.helpers.NamedLoggerBase.java
org.slf4j.helpers.SubstituteLoggerFactory.java
org.slf4j.helpers.Util.java
org.slf4j.impl.AndroidLoggerFactory.java
org.slf4j.impl.AndroidLogger.java
org.slf4j.impl.StaticLoggerBinder.java
org.slf4j.impl.StaticMDCBinder.java
org.slf4j.impl.StaticMarkerBinder.java
org.slf4j.spi.LocationAwareLogger.java
org.slf4j.spi.LoggerFactoryBinder.java
org.slf4j.spi.MDCAdapter.java
org.slf4j.spi.MarkerFactoryBinder.java