0

我在 VxWorks 上写了一些代码来从 TFTP 服务器下载文件,tftpLib但 get 给了我一个超时:

ERR [TFTP] tftpSend:479: Transfer Timed Out.
ERR [TFTP] tftpGet:1077: File transfer error.
Error has occurred: 4915207

这是不正确的,因为主机可以访问:

ping("3.94.213.53",3)

Pinging 3.94.213.53 (3.94.213.53) with 64 bytes of data:
Reply from 3.94.213.53 bytes=64 ttl=63 seq=0 time<1ms
Reply from 3.94.213.53 bytes=64 ttl=63 seq=1 time<1ms
Reply from 3.94.213.53 bytes=64 ttl=63 seq=2 time<1ms

当我从 Linux shell 执行此操作时,它按预期工作:

tftp -r "artifacts/ngfm.bin" -g 3.94.213.53

这里可能有什么问题?我的代码的 get 部分如下所示:

pFile = fopen("flash:/ngfm.bin","wb");
    if (pFile != NULL) {
        /* Get file from TFTP server and write it to the file descriptor */
        if (OK == (status = tftpGet (pTftpDesc, pFilename, pFile, TFTP_CLIENT))) {
         printf("tftpGet() successful\n");
        } else {
         printf("Error has occurred: %d\n", errno); // errno is where the error is stored
        }
    } else {
        printf("Bad file pointer pFile");
    }

编辑:

我在 get 部分上面的代码是:

/*Initiate TFTP session*/
if ((pTftpDesc = tftpInit ()) == NULL)
   printf("Error on tftpInit()\n");

/*connect to TFTP host and set transfer mode*/
if ((tftpPeerSet (pTftpDesc, pHost, port) == ERROR) ||
    (tftpModeSet (pTftpDesc, pMode) == ERROR)) {
    (void) tftpQuit (pTftpDesc);
    printf("Error on tftpPeerSet()\n");
    return ERROR;
}
4

2 回答 2

1

我相信您的问题是由于缺少调用tftpModeSet- http://www.vxdev.com/docs/vx55man/vxworks/ref/tftpLib.html#tftpModeSet

所以添加:

tftpModeSet(pTftpDesc, "binary");

这将防止您的二进制文件导致流在第一次死亡\n

于 2013-12-05T20:46:09.177 回答
0

好的,事实证明在我的情况下 TFTP 是不行的。我连接了 Wireshark 并看到我的客户端在端口 69 上可以很好地连接到服务器。我之前还确保在我的iptable规则中正确设置了端口 69 上的端口转发。现在我刚在维基百科上读到这个:

数据传输在端口 69 上启动,但数据传输端口在连接初始化期间由发送方和接收方独立选择。端口是根据网络堆栈的参数随机选择的,通常来自临时端口的范围

即 TFTP 对我不起作用,因为我需要 NAT 并且它必须是安全的。我需要使用面向连接的协议,例如 ftp

我发现标准VxWorks库还包含ftpLib.hhttp://www.vxdev.com/docs/vx55man/vxworks/ref/ftpLib.html#ftpLs),它有望解决我的 NAT 问题,因为 FTP 与基于连接的 TCP 一起工作。

于 2013-12-05T22:26:28.737 回答