guichaguri / minimalftp Goto Github PK
View Code? Open in Web Editor NEWA lightweight, simple FTP server. Pure Java, no dependencies.
License: Apache License 2.0
A lightweight, simple FTP server. Pure Java, no dependencies.
License: Apache License 2.0
Hi, I would like to implement a read only FTP server. How to do this? Do I need to disable some default command or other things?
Thank you.
Hi! I have found a bug!
You have to replace one line in your code:
FileHandler.list:236:
Object dir = args.length > 0 && !args[0].equals("-l") && !args[0].equals("-a") ? getFile(args[0]) : cwd;
Instead of:
Object dir = args.length > 0 && !args[0].equals("-l") ? getFile(args[0]) : cwd;
It doesn't work when client sends LIST -a. "-a" interprets as file that not exists. Client will have con.sendResponse(550, "Not a directory"); error.
After bug having been fixed you may do things like this:
sudo curlftpfs 127.0.0.1:2121 ~/mnt
Than you may exec command line commands like ls, cd, cat, rm -rf and so on this ftp server being mounted on local filesystem.
Specifically, how do we create a simple SSLContext to pass in?
// Creates a native file system
File ftpRootDir = getFtpRootDir();
NativeFileSystem fs = new NativeFileSystem(ftpRootDir);
// Creates a noop authenticator, which allows anonymous authentication
NoOpAuthenticator auth1 = new NoOpAuthenticator(fs);
// Creates a secure SSL server with the noop authenticator
server3 = new FTPServer(auth1);
server3.setExplicitSSL(false); // support SSL connections
SSLContext sslContext = howDoWeBuildSimpleSSLContext(); // ???
server3.setSSLContext(sslContext);
// Start listening asynchronously
server3.listen(InetAddress.getLoopbackAddress(), 3333);
Hi,
when delete() is called on a directory, is it called also recursively on its contents? In Filezilla it seems so, but I don't know if it's true in general.
I know that in a filesystem, deleting a directory deletes its contents, but I need to release resources for files.
Thanks again,
--Germano
PS: I don't use links, neither hard nor symbolic
I am currently trying to run a custom FTP implementation via Docker, and I am not able to expose all ports for PASV to work properly.
Specifying a port range would more or less resolve this issue, however just disabling PASV would be a great solution as well.
Currently, I re-register the PASV command on each connection to return 502 not implemented as a workaround, however this still trips up many FTP clients and gets the connection stuck.
An alternative solution would be to allow us to unregister commands & features on the fly.
Hi,
the class that implements IFileSystem must be thread safe, right? Are there methods that are called by one thread only? Is there a way to make everything "one thread only"?
Also, is it possible that two clients write on the same file, at the same time, so that the two OutputStream(s) must be "coordinated" (i.e., the second call to write() doesn't return until the close() method on the first OutputStream is called)? It's important for me to know this because the implementation is quite difficult, as it must take into account what happens when close() is not called because the client crashes.
I'm developing a project in which FTP is not backed by a filesystem, and so I can't use the out-of-the-box locking primitives of the "real" filesystem as you seem to do in the "reference" implementation.
Cheers, and thanks, and you did an excellent (excellent!) work,
--Germano
Improper closing by client causes infinite handling exception SocketException
inside IOException
catch block produced by reader.readline()
:
MinimalFTP/src/main/java/com/guichaguri/minimalftp/FTPConnection.java
Lines 558 to 568 in 801754d
Due to simple return
the thread ConnectionThread
hangs forever and consume a lot of CPU because of handling exceptions and filling stacktraces.
Hi,
I'm testing MinimalFTP under Linux (x86-64, Arch Linux, JVM 10.0.2) and it doesn't seem to work when accessing it from Filezilla. I thought it was my app, but the minimal code example in your README doesn't work either.
Please note that:
This is the Filezilla log:
Command: PWD
Response: 257 "/" CWD Name
Command: TYPE I
Response: 200 Type set to I
Command: PASV
Response: 227 Enabled Passive Mode (127,0,0,1,146,245)
Command: MLSD
Response: 150 Sending file information list...
Error: Data connection can't be estabilished. ECONNREFUSED - Connection refused by the server
(I translated from italian, sorry for any imprecision).
Thanks,
--Germano
Dear developer, I may find some problems in the program, please consider:
In your code, you use the function "com.guichaguri.minimalftp.handler.FileHandler.list(String args[]) ,line 230" to handle a receiving LIST command . But line 236
Object dir = args.length > 0 && !args[0].equals("-l") && !args[0].equals("-a") ? getFile(args[0]) : cwd;
may gets wrong dir.
In my opinion, if args[0] equals "-a", we should use arg[1] to get file rather than cwd. In this case, ftp client may use a Path as arg[1] to represent the directory, or "." to represent cwd.
And the second problem is that the function response wrong code to client when the path is not directory. Actually, some ftp client would use LIST command to get information of a file. So, ftp servers so response information in this case. When receiving a LIST command whith a path arg representing a file, just response like that the file is a directory than only has a file (itself) . I have read the source code of "org.apache.ftpserver.command.impl.LIST", which handles the LIST command in a Apache FTP server, and I find it do so.
The similar function nlst(String args[]) that handles NLST command may have same problems.
Crash log:
Caused by java.lang.IllegalArgumentException: Unknown pattern character 'Y'
at java.text.SimpleDateFormat.validatePatternCharacter(SimpleDateFormat.java:314)
at java.text.SimpleDateFormat.validatePattern(SimpleDateFormat.java:289)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:356)
at com.guichaguri.minimalftp.Utils.<clinit>(Utils.java:49)
at com.guichaguri.minimalftp.FTPServer.listen(FTPServer.java:201)
Problem line:
Crash platform:
According to Java SimpleDateFormat document, Year can be represented by lower case 'y', Upper case 'Y' represent Week year, which is not supported in lower version of Android. Maybe you can change to lower case y to improve compatibility on Android platform?
Hello,
first of all, thanks for sharing your work. I imported the sources and called it with the suggested code:
public static void main(String[] argv) throws IOException {
File root = new File(System.getProperty("user.dir"));
NativeFileSystem fs = new NativeFileSystem(root);
NoOpAuthenticator auth = new NoOpAuthenticator(fs);
FTPServer server = new FTPServer(auth);
server.listenSync(21);
}
When connecting to localhost:21 from Filezilla client, it fails almost immediately:
Comando: PWD
Risposta: 257 "/" CWD Name
Comando: TYPE I
Risposta: 200 Type set to I
Comando: EPSV
Risposta: 229 Enabled Passive Mode (|||52773|)
Comando: MLSD
Risposta: 501 Missing parameters
Errore: Non è stato possibile leggere il contenuto della cartella
Sorry for the italian, the last line means "it wasn't possible to read the contents of the folder". Am I missing something?
Cheers, and thanks again,
Germano
Hello thanks for the nice library.
Is there a way to specify passive port range?
Regards, Fatih
Please allow us to customize the buffer size.
Exception in thread "Thread-97" java.lang.NullPointerException
at com.guichaguri.minimalftp.FTPConnection.sendResponse(FTPConnection.java:198)
at com.guichaguri.minimalftp.FTPConnection.processCommand(FTPConnection.java:519)
at com.guichaguri.minimalftp.FTPConnection.process(FTPConnection.java:444)
at com.guichaguri.minimalftp.FTPConnection.update(FTPConnection.java:556)
at com.guichaguri.minimalftp.FTPConnection$ConnectionThread.run(FTPConnection.java:603)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.