Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 请求-应答中的源端口(69)不正确。TFTP发送文件_Java_Io_Ftp_Network Programming_Tftp - Fatal编程技术网

Java 请求-应答中的源端口(69)不正确。TFTP发送文件

Java 请求-应答中的源端口(69)不正确。TFTP发送文件,java,io,ftp,network-programming,tftp,Java,Io,Ftp,Network Programming,Tftp,我试图通过Java中的TFTP客户端执行此TFTP DOS send命令: tftp -i 192.168.1.13 put file1.romz file1.romz 这意味着以二进制方式将文件file1.romz发送到主机192.168.1.13,并在到达file1.romz时重命名该文件。大约 代码如下: import java.io.FileInputStream; import java.io.IOException; import java.net.SocketException;

我试图通过Java中的TFTP客户端执行此TFTP DOS send命令:

tftp -i 192.168.1.13 put file1.romz file1.romz
这意味着以二进制方式将文件file1.romz发送到主机192.168.1.13,并在到达file1.romz时重命名该文件。大约

代码如下:

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();
}