Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > 服务器相关 > 堆代码啦,堆个vxworks下的tftp和ftp的。
【标  题】:堆代码啦,堆个vxworks下的tftp和ftp的。
【关键字】:vxworks,tftp,ftp
【来  源】:http://www.cublog.cn/u/20871/showart.php?id=214669

堆代码啦,堆个vxworks下的tftp和ftp的。

Your Ad Here
/*
this program is test for download core from host usr using tftp
*/

#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include "vxWorks.h"
#include "tftpLib.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;

}
/*
next is download files from host using ftp 
*/
 
 
/* vxFtpClient.c - Demo for using FTP communication between FTP client
 *                 running on a VxWorks target and  remote FTP server
 *                 running on a UNIX host
 */
 
/* Copyright 1984-1997 Wind River Systems, Inc. */
/*
modification history
--------------------
01c,06nov97,mm     added copyright.
01b,15Sep97,mm     added <errno.h> <stdio.h> <unistd.h>
01a,18feb94,ms     written
*/
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include "vxWorks.h"
#include "ftpLib.h"
 
#define UNIX_HOST  "192.1.200.32"    /* inet address of the remote UNIX host */
#define USER       "john"              /* your login user name */
#define PASSWD     "iluvwrs"           /* your login passwd    */
#define W_DIR     "/sevana1/john/VxDemo/net/ftp/" /* cd to working directory */
#define RD_CMND    "RETR %s"           /* read a remote file FTP command */
#define QUIT_CMND  "QUIT"              /* quit FTP command */
#define FILE       "ftpData.txt"       /* file to request - located in W_DIR */
/*****************************************************************************
 * ftpReadDemo -  reads a remote file on a UNIX host using FTP commands
 *
 *  CONFIGURATION:
 *
 *  You need to set/change the value of the UNIX_HOST, USER, PASSWD and W_DIR
 *  constants given in this file.
 * 
 *  EXAMPLE:
 *
 *     To run ftpReadDemo, from the VxWorks shell do as follows:
 *     -> sp ftpReadDemo
 *
 *  RETURNS: OK or ERROR
 */
STATUS ftpReadDemo ()
    {
    int ctrlSock;
    int dataSock;
    char buffer [512];
    int numBytes;
 
    buffer [0] = '\0';
    /* initiate a transfer via a remote FTP server to read a remote file */
    if (ftpXfer (UNIX_HOST, USER, PASSWD, "", RD_CMND, W_DIR,
                                    FILE, &ctrlSock, &dataSock) == ERROR)
        {
        perror ("Error in initiating a transfer via a remote FTP server"); 
        return (ERROR);
        }
    /* read the remote file - for this example it is assumed that the amount
     * of buffer that needs to be read is less than 512 bytes
     */
    while ((numBytes = read (dataSock, buffer, sizeof (buffer))) > 0)
        {
        /* Do some processing here */
        printf ("\nData read: ");
        write (STD_OUT, buffer, numBytes);
        printf ("\n");
        }
    if (numBytes < 0)
        {
        perror ("Error in reading");          /* read error */
        return (ERROR);
        }
    close (dataSock);
    /* Get an FTP command reply to see whether EOF is encountered */
    if (ftpReplyGet (ctrlSock, TRUE) != FTP_COMPLETE)
        {
        perror ("positive completion failed");
        return (ERROR);
        }
    /* Send QUIT FTP command */
    if (ftpCommand (ctrlSock, QUIT_CMND, 0, 0, 0, 0, 0, 0) != FTP_COMPLETE)
        {
        perror ("QUIT FTP command positive completion failed");
        return (ERROR);
        }
    close (ctrlSock);
    return (OK);
    }

 
vsftp配置大全---超完整版- -:【上一篇】
在RHEL AS4 下安装Bind 9.3.3:【下一篇】
【相关文章】
  • vsftp配置大全---超完整版- -
  • pure-ftpd在debian上的简单使用
  • 关于serv-u ftp管理员帐号在命令行下登陆可建里系统(win)帐号问题
  • 最近在关注冰岩作坊自己写的一个ftp的搜索
  • FTP传送与获取文件收集
  • FTP 协议(rfc939) 简单的实验(in Java)
  • PureFTPd配置文件
  • 如何设置pkg_add -r时从哪个FTP下载?
  • FTP下载的函数
  • 自动FTP脚本:
  • 【随机文章】
  • 第七章 Unix进程的环境
  • 考考你的C++水平
  • VIU-323视讯界面器
  • install oracle10g 10.1.0.3 on RHEL3(By Werner Puschitz)
  • 网络服务器
  • JScript 方法 - charAt 方法
  • win2000密码破解不完全指南(下)
  • 在Java2环境中应用IP地址封装对象
  • 一次解压缩同目录下的 .tar.gz 文件
  • Exim畸形EHLO/HELO命令远程堆破坏漏洞
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.