org.apache.ftpserver.ftplet.FtpFile Java Examples

The following examples show how to use org.apache.ftpserver.ftplet.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: FtpCollectionFile.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public List<FtpFile> listFiles ()
{
   List<FtpFile> children = new ArrayList<> ();
   Iterator<Product> it = collectionService.getAuthorizedProducts (
         collection.getUUID (), null).iterator ();

   while (it.hasNext ())
   {
      Product product = it.next ();
      if (product != null)
      {
         children.add (new FtpProductFile (super.user, collection, product));
      }
   }

   children.add (new FtpContentDateFile (user, collection));

   return children;
}
 
Example #2
Source File: DHuSFtpProductViewByCollection.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public FtpFile getWorkingDirectory () throws FtpException
{
   if (currentPath.contains (CONTENT_DATE))
   {
      return new FtpContentDateFile (user, workingCol,
            pathInfo.get (DATE_YEAR), pathInfo.get(DATE_MONTH),
            pathInfo.get(DATE_DAY));
   }

   if (workingCol == null)
   {
      return getHomeDirectory ();
   }
   else
   {
      return new FtpCollectionFile (user, workingCol);
   }
}
 
Example #3
Source File: BaseUriFtpFile.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
@Override
public List<? extends FtpFile> listFiles() {
    if (!mDocument.exists() || !mDocument.isDirectory())
        return null;
    final DocumentFile[] children = mDocument.listFiles();
    if (children.length <= 0)
        return new ArrayList<>(0);
    final ArrayList<BaseUriFtpFile> files = new ArrayList<>(children.length);
    for (DocumentFile child : children) {
        final String absolutePath = mAbsolutePath + "/" + child.getName();
        final BaseUriFtpFile item = onCreateChild();
        item.set(mContentResolver, child, absolutePath);
        files.add(item);
    }
    return files;
}
 
Example #4
Source File: FtpRootFile.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<FtpFile> listFiles ()
{
   List<FtpFile> children = new ArrayList<> ();
   Iterator<Collection> collectionIterator =
         super.collectionService.getAuthorizedCollection (user).iterator ();

   // retrieve collection directory
   while (collectionIterator.hasNext ())
   {
      Collection collection = collectionIterator.next ();
      if (collection != null)
      {
         children.add (new FtpCollectionFile (super.user, collection));
      }
   }

   // retrieve product file
   Iterator<Product> productIterator =
         productService.getNoCollectionProducts ().iterator ();
   while (productIterator.hasNext ())
   {
      children.add (new FtpProductFile (user, null, productIterator.next ()));
   }

   // view by ingestion date
   children.add (new FtpContentDateFile (user, null));

   return children;
}
 
Example #5
Source File: DHuSFtpProductViewByCollection.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public FtpFile getFile (String name) throws FtpException
{
   if (name.equals ("./"))
   {
      return getWorkingDirectory ();
   }

   String identifier = name.substring (0, (name.length () - 4));
   Product p = productService.getProductIdentifier (identifier);
   return new FtpProductFile (user, workingCol, p);
}
 
Example #6
Source File: FtpProductFile.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<FtpFile> listFiles ()
{
   return null;
}
 
Example #7
Source File: DHuSFtpProductViewByCollection.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FtpFile getHomeDirectory () throws FtpException
{
   return new FtpRootFile (user);
}
 
Example #8
Source File: DHuSFtpFile.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public final boolean move (FtpFile ftpFile)
{
   throw new UnsupportedOperationException ("FTP server is Read Only");
}
 
Example #9
Source File: FileFtpFile.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
@Override
public boolean move(FtpFile destination) {
    return mFile.renameTo(new File(destination.getAbsolutePath()));
}
 
Example #10
Source File: FtpFileWrapper.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean move(FtpFile destination) {
    return controller.renameFile(this.unwrap(), destination.getName());
}
 
Example #11
Source File: FtpFileWrapper.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<FtpFile> listFiles() {
    return view.listFiles(this);
}
 
Example #12
Source File: FtpCommands.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Execute command.
 */
public void execute(final FtpIoSession session, final FtpServerContext context, final FtpRequest request) {

    // reset state variables
    session.resetState();

    String argument = request.getArgument();

    if (argument == null || argument.trim().length() == 0) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "MFMT.invalid", null));
        return;
    }

    String[] arguments = argument.split(" ", 2);

    if (arguments.length != 2) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "MFMT.invalid", null));
        return;
    }

    String timestamp = arguments[0].trim();

    try {

        Date time = DateUtils.parseFTPDate(timestamp);

        String fileName = arguments[1].trim();

        // get file object
        FtpFile file = null;

        try {
            file = session.getFileSystemView().getFile(fileName);
        } catch (Exception ex) {
            LOG.debug("Exception getting the file object: " + fileName, ex);
        }

        if (file == null || !file.doesExist()) {
            session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_550_REQUESTED_ACTION_NOT_TAKEN,
                    "MFMT.filemissing", fileName));
            return;
        }

        // INFO: We want folders also to be touched
        // // check file
        // if (!file.isFile()) {
        // session.write(LocalizedFtpReply
        // .translate(
        // session,
        // request,
        // context,
        // FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
        // "MFMT.invalid", null));
        // return;
        // }

        // check if we can set date and retrieve the actual date
        // stored
        // for the file.
        if (!file.setLastModified(time.getTime())) {
            // we couldn't set the date, possibly the file was
            // locked
            session.write(LocalizedFtpReply.translate(session, request, context,
                    FtpReply.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN, "MFMT", fileName));
            return;
        }

        // all checks okay, lets go
        session.write(LocalizedFtpReply.translate(session, request, context, FtpReply.REPLY_213_FILE_STATUS, "MFMT",
                "ModifyTime=" + timestamp + "; " + fileName));

    } catch (ParseException e) {
        session.write(LocalizedFtpReply.translate(session, request, context,
                FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "MFMT.invalid", null));
    }

}