我在 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;
}