免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 8197 | 回复: 12
打印 上一主题 下一主题

[SCO UNIX] sco unix ftp 源代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-01-23 15:17 |只看该作者 |倒序浏览
如下代码可以实现 unix to unix 的文件发送,但不通实现unix to windows之间的发送,各位指点指点。

#include <stdio.h>;
  #include <net/libftp.h>;

  #define NORMAL  0
  #define ABNORMAL        1
  #define ON              1
  #define OFF             0

  main (argc, argv)
          int     argc;
          char    *argv[];
  {
          FTPINFO ftpinfo;      
          void    usage(), check_n_close();
          char    *progname;
          char    *host;
         
          progname = (char *) argv[0];
          if ( argc < 2 )
                  (void) usage(progname);

          host = argv[1];
          ftpinfo.debug = ON;
          ftpinfo.transf_calc = ON;
          ftpinfo.linger = OFF;

          /*
           * connect to peer at remote host.
           */
          if (ftp_prconnect ( &amp;ftpinfo, host ) < 0) {
                  printf("error: ftp_prconnect failed.\n";      
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * send user name to the remote server.
           */
          if (ftp_user( &amp;ftpinfo, "bank" ) < 0) {
                  printf("error: ftp_user failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * send user password to the remote server.
           */
          if (ftp_passwd ( &amp;ftpinfo, "" ) < 0) {
                  printf("error: ftp_passwd failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }      
                 
          /*
           * set the idle time for this connection.
           */
          if (ftp_idle ( &amp;ftpinfo, "7200" ) < 0) {
                  printf("error: ftp_idle failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }
         
          /*
           * do a 'cd' on the remote ftp server.
           */
          if (ftp_chdir( &amp;ftpinfo, "winnt" ) < 0) {
                  printf("error: ftp_chdir failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * do a 'pwd' on the remote ftp server.
           */
          if (ftp_pwd ( &amp;ftpinfo ) < 0) {
                  printf("error: ftp_pwd failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * set transfer mode to ascii.
           */
          if (ftp_ascii ( &amp;ftpinfo ) < 0) {
                  printf("error: ftp_ascii failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * set transfer mode to binary.
           */
          if (ftp_binary ( &amp;ftpinfo ) < 0) {
                  printf("error: ftp_binary failed.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * set transfer mode back to ascii - using ftp_settype.
           */
          if (ftp_settype ( &amp;ftpinfo, ASCII ) < 0) {
                  printf("error: ftp_settype failed in ascii mode.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * set transfer mode back to binary - using ftp_settype.
           */
          if (ftp_settype ( &amp;ftpinfo, BINARY ) < 0) {
                  printf("error: ftp_settype failed in binary mode.\n";
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * make a directory under /tmp on the server.
           */
          if (ftp_mkdir ( &amp;ftpinfo, "prem" ) < 0) {
                  printf("error: ftp_mkdir failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }
                 
          /*
           * change the mode of the directory created above.
           */
          if (ftp_site ( &amp;ftpinfo, "chmod 775 prem" ) < 0) {
                  printf("error: ftp_site failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * remove the directory created above.
           */
          if (ftp_rmdir ( &amp;ftpinfo, "prem" ) < 0) {
                  printf("error: ftp_rmdir failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * quit the FTP session decently.
           */
          if (ftp_bye( &amp;ftpinfo ) < 0) {
                  printf("error: ftp_bye failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * use ftp_login to login into the remote ftp server and quit.
           */
          if (ftp_login ( &amp;ftpinfo, host, "bank", "", NULL ) < 0) {
                  printf("error: ftp_login failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * do a 'put' to the remote host.
           */
          if (ftp_putfile ( &amp;ftpinfo, "/tmp/passwd", "c:/passwd" ) < 0) {
                  printf("error: ftp_putfile failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }
          else {
                  printf("transfer speed: \n");
                  printf("\t\tbytes transferred = %ld\n",
                                  ftpinfo.speed.size_bytes);
                  printf("\t\ttime taken        = %.2g seconds\n",
                                  ftpinfo.speed.seconds);                        
                  printf("\t\trate              = %.2g Kbytes/s\n",
                                  ftpinfo.speed.kbs);
          }

          /*
           * set transfer mode back to ascii - using ftp_settype.
           */
          if (ftp_settype ( &amp;ftpinfo, ASCII ) < 0) {
                  printf("error: ftp_settype failed in ascii mode.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * do a 'get' from the remote host.
           */
          if (ftp_getfile ( &amp;ftpinfo, "/tmp/passwd","c:/passwd" )< 0){
                  printf("error: ftp_getfile failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }
          else {
                  printf("transfer speed: \n");
                  printf("\t\tbytes transferred = %ld\n",
                                  ftpinfo.speed.size_bytes);
                  printf("\t\ttime taken       = %.2g seconds\n",
                                  ftpinfo.speed.seconds);                        
                  printf("\t\trate             = %.2g Kbytes/s\n",
                                  ftpinfo.speed.kbs);
          }

          /*
           * list /tmp on remote host to file /tmp/test.
           */
          if (ftp_dir ( &amp;ftpinfo, "/tmp", "/tmp/test" ) < 0) {
                  printf("error: ftp_dir failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * list /tmp on remote host to stdout.
           */
          if (ftp_dir ( &amp;ftpinfo, "/tmp", NULL ) < 0) {
                  printf("error: ftp_dir failed to write to stdout.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * delete the file on the remote host.
           */
          if (ftp_del ( &amp;ftpinfo, "/tmp/asciifile" ) < 0) {
                  printf("error: ftp_del failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * quit the FTP sessions decently.
           */
          if (ftp_bye( &amp;ftpinfo ) < 0) {
                  printf("error: ftp_bye failed.\n");
                  (void) check_n_close ( &amp;ftpinfo, ABNORMAL );
          }

          /*
           * we're done with our job...so exit the program gracefully.
           */
          (void) check_n_close ( &amp;ftpinfo, NORMAL );     

  }


  void
  usage(progname)
          char *progname;
  {
          printf("usage: %s <remhost>;\n", progname);
          exit (1);
  }

  void
  check_n_close ( ftpinfo, status )
          FTPINFO *ftpinfo;
          int     status;
  {
          if (ftpinfo ->; sockfd >;= 0)
                  close (ftpinfo ->; sockfd);
          if (status == ABNORMAL)
                  printf("error: %s\n", ftpinfo ->; ftp_msg);
          else
                  printf("success: %s\n", ftpinfo ->; ftp_msg);

          printf("final reply from server: %d\n", ftpinfo ->; reply);
          fflush ( stdout );
          exit (status);
  }

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2003-01-23 15:39 |只看该作者

sco unix ftp 源代码

ok

论坛徽章:
0
3 [报告]
发表于 2003-01-23 16:21 |只看该作者

sco unix ftp 源代码

怎么样编译。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
4 [报告]
发表于 2003-01-23 19:31 |只看该作者

sco unix ftp 源代码

cc  prog.c -o prog -lftp

论坛徽章:
0
5 [报告]
发表于 2003-01-23 19:33 |只看该作者

sco unix ftp 源代码

加为精华吧

论坛徽章:
0
6 [报告]
发表于 2003-01-24 13:20 |只看该作者

sco unix ftp 源代码

难道没有人作过吗?

论坛徽章:
0
7 [报告]
发表于 2003-02-03 02:55 |只看该作者

sco unix ftp 源代码

我没用过ftp库函数,用普通socket函数到是写过,
效果还不错,一直在用!

论坛徽章:
0
8 [报告]
发表于 2004-04-29 09:40 |只看该作者

sco unix ftp 源代码

请问老大, 我的机器怎么有一个提示/usr/lib/libftp.a 的提示呀!
编译没有其他的错误,希望指点一二,谢谢!

论坛徽章:
0
9 [报告]
发表于 2004-05-20 15:02 |只看该作者

sco unix ftp 源代码

各位老大:编译的问题解决了,命令如下:  cc -o ftp ftp.c -llftp -lsocket
可是运行时出现错误如下:
error: fopen failed to open in "r" mode for sending
final reply from server: 150

error: ftp _ftpfile failed
ferror:data connection failed
inal reply from server: 553
那位能帮我解决!这里先行谢过了!

论坛徽章:
0
10 [报告]
发表于 2004-07-13 16:13 |只看该作者

sco unix ftp 源代码

man ftp看到最后就是上面的例程了,只有unixware下能够使用,必须链接libftp.a,其他系统用不了的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP