Giter Club home page Giter Club logo

ftpserver's Introduction

FtpServer: Android FTP server library, embed a FTP server into the Android application you are developing

Summary

This is an Android library, the title has explained its functionality.

Source code: https://github.com/hxcan/ftpserver

Reference application: https://github.com/hxcan/hxftpserver

Add dependency

Follow the instructions here: https://jitpack.io/#hxcan/ftpserver

Remember to replace the Tag to the latest tag value, currently it is โ€œ2023.10.24โ€.

Start the FTP server

Refer to the code in the reference application: https://github.com/hxcan/hxftpserver/commit/5485145393444b69a671b2e87739548e83309e11#diff-b9a19f3b2f9a51896a8fe8a0ca05b1723c5557557a68123cf8cdd81458256889R99

Stop the FTP server

Refer to the code in the reference application: https://github.com/hxcan/hxftpserver/commit/9986d76048041ff8ea8c15acddc28bec95350396#diff-b9a19f3b2f9a51896a8fe8a0ca05b1723c5557557a68123cf8cdd81458256889R125

To support more FTP clients

If your FTP client did not work well with this FTP server, please report an issue: https://github.com/hxcan/ftpserver/issues

Build this project yourself

The oldest version of jdk supported by this project is openjdk11. The latest version of jdk supported by this project is openjdk19. You need a jdk who's version is in this range, to compile this project successfully.

How to set the jdk version in Android Studio: https://stackoverflow.com/a/75114912

Mysterious text

################### #"#$#&#(#*#,#.#0#2#4#6#8#:#<#>#@#B

ftpserver's People

Contributors

hxcan avatar

Stargazers

 avatar

Watchers

 avatar

ftpserver's Issues

How to stop the FTP server?

I was able to successfully implement your library in my app, but one essential thing is missing for me: How to stop the server?
Do you have an idea?
Thank you for this good work.

In wifi hotspot mode, ftpserver can not work normally

When phone is in the hotspot mode, the FTP server can't get host IP address (only show 0.0.0.0:port), and then FTP client can't
connect to FTP server. If the phone is in the wifi station mode, the FTP server can get host IP address and FTP client can connect correctly to the FTP server.

No support for RNFR and RNTO commands to rename or move files

Here is what I suggest that works for me:

add in the processCommand method of ControlConnectHandler class:

public void processCommand(String command, String content, boolean hasFolloingCommand) {
	......
    else if (command.equalsIgnoreCase("RNFR")){
        String data51= content.substring(5);
        data51=data51.trim();
        processRenameFromCommand(data51);
    }
    else if (command.equalsIgnoreCase("RNTO")){
        String data51= content.substring(5);
        data51=data51.trim();
        processRenameToCommand(data51);
    }
	..........
}

add methods:

/**
   *  Process the rename command
   */
    private void processRenameFromCommand(String data51){
      if (!allowWrite){ // A boolean that I added in the case where writing to the server is not authorized
        binaryStringSender.sendStringInBinaryMode("550 Writing permission not granted.");
        return;
      }
      Log.d("renameCommandFrom","data51 "+data51);
      Log.d("renameCommandFrom","rootDirectory "+rootDirectory);
      Log.d("renameCommandFrom","currentWorking "+currentWorkingDirectory);
      currentWorkingDirectory = currentWorkingDirectory.replace("//","/");
      // add a field oldPath
      if (data51.startsWith("/")){
        this.oldPath = rootDirectory.getPath() +data51;
      }else {
        this.oldPath = rootDirectory.getPath() + currentWorkingDirectory+"/"+data51;
      }
      Log.d("renameCommand","oldPath "+oldPath);
      binaryStringSender.sendStringInBinaryMode("350 File to rename: "+currentWorkingDirectory+"/"+data51);
    }

  /**
   *  Process the rename command
   */
  private void processRenameToCommand(String data51){
    Log.d("renameCommandTo","data51 "+data51);
    String newPath = rootDirectory.getPath()+data51;
    Log.d("renameCommandTo","newPath "+newPath);
    if (renameFile(this.oldPath,newPath)){
      binaryStringSender.sendStringInBinaryMode("250 Success! renamed to: "+data51);
    }else {
      binaryStringSender.sendStringInBinaryMode("500 Failed! renamed to: "+data51);
    }

  }

  public static boolean renameFile(String oldFileName, String newFileName) {
    File oldFile = new File(oldFileName);
    File newFile = new File(newFileName);

    if (oldFile.exists()) {
      boolean success = oldFile.renameTo(newFile);
      return success;
    } else {
      return false; // Le fichier source n'existe pas.
    }
  }

allowWrite is a boolean that I added to the FtpServer and ConneConnectHandler constructor for my implementation.

Thanks!

What is the default login?

I'm running the server perfectly, but i don't know what is the default login.
Another question, is if there is some function to change the user and the password for the login.
Good night.

Android 11+

Will you implement DocumentFile and scoped storage except old File way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.