Skip to content

Commit

Permalink
Added MMD5 command
Browse files Browse the repository at this point in the history
  • Loading branch information
Guichaguri committed Jun 18, 2018
1 parent d979fa2 commit 7edccd1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ The required minimum implementation is already done, however, there are still co
* [RFC 2389](https://tools.ietf.org/html/rfc2389) - Feature negotiation mechanism for the File Transfer Protocol (2/2)
* [RFC 2428](https://tools.ietf.org/html/rfc2428) - FTP Extensions for IPv6 and NATs (2/2)
* [RFC 2640](https://tools.ietf.org/html/rfc2640) - Internationalization of the File Transfer Protocol (0/1)
* [RFC 2773](https://tools.ietf.org/html/rfc2773) - Encryption using KEA and SKIPJACK
* [RFC 2773](https://tools.ietf.org/html/rfc2773) - Encryption using KEA and SKIPJACK (0/1)
* [RFC 3659](https://tools.ietf.org/html/rfc3659) - Extensions to FTP (4/4)
* [RFC 4217](https://tools.ietf.org/html/rfc4217) - Securing FTP with TLS
* [RFC 5797](https://tools.ietf.org/html/rfc5797) - FTP Command and Extension Registry
* [RFC 7151](https://tools.ietf.org/html/rfc7151) - File Transfer Protocol HOST Command for Virtual Hosts (0/1)
* [draft-twine-ftpmd5-00](https://tools.ietf.org/html/draft-twine-ftpmd5-00) - The "MD5" and "MMD5" FTP Command Extensions (1/2) (Obsolete)
* [draft-twine-ftpmd5-00](https://tools.ietf.org/html/draft-twine-ftpmd5-00) - The "MD5" and "MMD5" FTP Command Extensions (2/2) (Obsolete)
* [draft-somers-ftp-mfxx-04](https://tools.ietf.org/html/draft-somers-ftp-mfxx-04) - The "MFMT", "MFCT", and "MFF" Command Extensions for FTP (1/3)
* [draft-bryan-ftpext-hash-02](https://tools.ietf.org/html/draft-bryan-ftpext-hash-02) - File Transfer Protocol HASH Command for Cryptographic Hashes (1/1)
* [draft-bryan-ftp-range-08](https://tools.ietf.org/html/draft-bryan-ftp-range-08) - File Transfer Protocol RANG Command for Octet Ranges (0/1)
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/com/guichaguri/minimalftp/handler/FileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void registerCommands() {
con.registerCommand("MFMT", "MFMT <time> <file>", this::mfmt); // Change Modified Time (draft-somers-ftp-mfxx-04)

con.registerCommand("MD5", "MD5 <file>", this::md5); // MD5 Digest (draft-twine-ftpmd5-00) (Obsolete)
con.registerCommand("MMD5", "MMD5 <file1, file2, ...>", this::mmd5); // MD5 Digest (draft-twine-ftpmd5-00) (Obsolete)

con.registerCommand("HASH", "HASH <file>", this::hash); // Hash Digest (draft-bryan-ftpext-hash-02)

Expand Down Expand Up @@ -392,12 +393,47 @@ private void mfmt(String[] args) throws IOException {
}

private void md5(String path) throws IOException {
String p = path = path.trim();

if(p.length() > 2 && p.startsWith("\"") && p.endsWith("\"")) {
// Remove the quotes
p = p.substring(1, p.length() - 1).trim();
}

try {
Object file = getFile(path);
Object file = getFile(p);
byte[] digest = fs.getDigest(file, "MD5");
String md5 = DatatypeConverter.printHexBinary(digest);

con.sendResponse(251, fs.getName(file) + " " + md5);
con.sendResponse(251, path + " " + md5);
} catch(NoSuchAlgorithmException ex) {
// Shouldn't ever happen
con.sendResponse(504, ex.getMessage());
}
}

private void mmd5(String args) throws IOException {
String[] paths = args.split(",");
StringBuilder response = new StringBuilder();

try {
for(String path : paths) {
String p = path = path.trim();

if(p.length() > 2 && p.startsWith("\"") && p.endsWith("\"")) {
// Remove the quotes
p = p.substring(1, p.length() - 1).trim();
}

Object file = getFile(p);
byte[] digest = fs.getDigest(file, "MD5");
String md5 = DatatypeConverter.printHexBinary(digest);

if(response.length() > 0) response.append(", ");
response.append(path).append(" ").append(md5);
}

con.sendResponse(paths.length == 1 ? 251 : 252, response.toString());
} catch(NoSuchAlgorithmException ex) {
// Shouldn't ever happen
con.sendResponse(504, ex.getMessage());
Expand Down

0 comments on commit 7edccd1

Please sign in to comment.