请求回复中的源端口(69)不正确。 TFTP SENDFILE
问题描述:
我特林执行此TFTP DOS通过TFTP客户端在Java中发出命令:请求回复中的源端口(69)不正确。 TFTP SENDFILE
tftp -i 192.168.1.13 put file1.romz file1.romz
这意味着将文件发送file1.romz主办:192.168.1.13,以二进制方式重命名文件到达file1.romz时。关于TFTP DOS command。
这是代码:
import java.io.FileInputStream;
import java.io.IOException;
import java.net.SocketException;
import java.net.UnknownHostException;
import org.apache.commons.net.tftp.TFTP;
import org.apache.commons.net.tftp.TFTPClient;
public class TFTPClientToSend {
public final static void main(String[] args) {
boolean closed;
int transferMode = TFTP.BINARY_MODE;
String hostname, localFilename, remoteFilename;
TFTPClient tftp;
// Get host and file arguments
hostname = "192.168.1.13";
localFilename = "file1.romz";
remoteFilename = "file1.romz";
// Create our TFTP instance to handle the file transfer.
tftp = new TFTPClient();
// We want to timeout if a response takes longer than 60 seconds
tftp.setDefaultTimeout(60000);
// Open local socket
try {
tftp.open();
} catch (SocketException e) {
System.err.println("Error: could not open local UDP socket.");
System.err.println(e.getMessage());
System.exit(1);
}
// We haven't closed the local file yet.
closed = false;
// We're sending a file
FileInputStream input = null;
// Try to open local file for reading
try {
input = new FileInputStream(localFilename);
} catch (IOException e) {
tftp.close();
System.err.println("Error: could not open local file for reading.");
System.err.println(e.getMessage());
System.exit(1);
}
// Try to send local file via TFTP
try {
tftp.sendFile(remoteFilename, transferMode, input, hostname, 69);
} catch (UnknownHostException e) {
System.err.println("Error: could not resolve hostname.");
System.err.println(e.getMessage());
System.exit(1);
} catch (IOException e) {
System.err.println(
"Error: I/O exception occurred while sending file.");
System.err.println(e.getMessage());
System.exit(1);
} finally {
// Close local socket and input file
tftp.close();
try {
input.close();
closed = true;
} catch (IOException e) {
closed = false;
System.err.println("Error: error closing file.");
System.err.println(e.getMessage());
}
}
if (!closed) {
System.exit(1);
}
}
}
的领域是正确的,但我得到了以下错误消息:
Error: I/O exception occurred while sending file.
Incorrect source port (69) in request reply.
的TFTP UDP端口号是正式69. Windows防火墙是关闭的,TFTP Lantronix服务器可以通过TFTP更新新的软件。 Java随机使用端口在字符串的第一帧中发送数据。我想这就是为什么我有这个错误信息。你怎么能改变这个源端口?或者是导致这个错误的另一个问题?
在此先感谢。
答
就像解决方法。我用它来执行Java中的Windows DOS命令。
try {
Process proceso = Runtime.getRuntime().exec("tftp -i 192.168.1.13 put
file1.romz file1.romz");
} catch (IOException e) {
e.printStackTrace();
}