You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2017/02/09 16:30:43 UTC
svn commit: r1782366 -
/commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java
Author: sebb
Date: Thu Feb 9 16:30:42 2017
New Revision: 1782366
URL: http://svn.apache.org/viewvc?rev=1782366&view=rev
Log:
Add verbose mode
Modified:
commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java
Modified: commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java?rev=1782366&r1=1782365&r2=1782366&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java (original)
+++ commons/proper/net/trunk/src/main/java/examples/ftp/TFTPExample.java Thu Feb 9 16:30:42 2017
@@ -26,6 +26,7 @@ import java.net.SocketException;
import java.net.UnknownHostException;
import org.apache.commons.net.tftp.TFTP;
import org.apache.commons.net.tftp.TFTPClient;
+import org.apache.commons.net.tftp.TFTPPacket;
/***
* This is an example of a simple Java tftp client.
@@ -58,15 +59,18 @@ public final class TFTPExample
"\t-s Send a local file\n" +
"\t-r Receive a remote file\n" +
"\t-a Use ASCII transfer mode\n" +
- "\t-b Use binary transfer mode\n";
+ "\t-b Use binary transfer mode\n" +
+ "\t-v Verbose (trace packets)\n"
+ ;
public static void main(String[] args)
{
boolean receiveFile = true, closed;
int transferMode = TFTP.BINARY_MODE, argc;
String arg, hostname, localFilename, remoteFilename;
- TFTPClient tftp;
+ final TFTPClient tftp;
int timeout = 60000;
+ boolean verbose = false;
// Parse options
for (argc = 0; argc < args.length; argc++)
@@ -84,6 +88,8 @@ public final class TFTPExample
transferMode = TFTP.BINARY_MODE;
} else if (arg.equals("-t")) {
timeout = 1000*Integer.parseInt(args[++argc]);
+ } else if (arg.equals("-v")) {
+ verbose = true;
} else {
System.err.println("Error: unrecognized option.");
System.err.print(USAGE);
@@ -108,7 +114,16 @@ public final class TFTPExample
remoteFilename = args[argc + 2];
// Create our TFTP instance to handle the file transfer.
- tftp = new TFTPClient();
+ if (verbose) {
+ tftp = new TFTPClient() {
+ @Override
+ protected void trace(String direction, TFTPPacket packet) {
+ System.out.println(direction + " " + packet);
+ }
+ };
+ } else {
+ tftp = new TFTPClient();
+ }
// We want to timeout if a response takes longer than 60 seconds
tftp.setDefaultTimeout(timeout);