#include "vxworks.h"
#include "tftpLib.h"
#include "stdio.h"
#define BUFFERSIZE 1024
STATUS tftp( char* host, char* fileName, char* desFile )
{
int dataFd, total = 0;
int errorFd;
int fd, num;
char buf [BUFFERSIZE + 1];
printf("Please wait ...\r\n");
remove ( desFile);
fd=open(desFile,2,0644);
if (ERROR==fd)
{
creat(desFile,2);
fd=open(desFile,2,0644);
if(fd == ERROR)
{
printf("Can not open the destination file\r\n");
return ERROR;
}
}
if (tftpXfer (host, 0, fileName, "get", "binary", &dataFd, &errorFd) == ERROR)
{
printf("Can not establish link to host %s\r\n",host);
return (ERROR);
}
while ((num = read (dataFd, buf, sizeof (buf))) > 0)
{
total += num;
write(fd, buf, num);
}
close(fd);
close (dataFd);
if( total >0 )
printf("File Transfered Successfully!\r\n ");
else
printf("File Transfered Failed!\r\n ");
close (errorFd);
return OK;
}