免费注册 查看新帖 |

Chinaunix

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

linux下c编程实现ftp上传文件的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-02 16:48 |只看该作者 |倒序浏览
我想请问一下,在实现ftp上传文件的时候,c是不是只能用read(),write()函数以字节的形式传文件,那如果是想以文件级上传,应该是怎样实现呢,调用何种函数?谢谢

论坛徽章:
0
2 [报告]
发表于 2007-03-02 22:22 |只看该作者
原帖由 blueskyww 于 2007-3-2 16:48 发表于 1楼  
我想请问一下,在实现ftp上传文件的时候,c是不是只能用read(),write()函数以字节的形式传文件,那如果是想以文件级上传,应该是怎样实现呢,调用何种函数?谢谢

>>
>>
>>好像没有现成的直接传送文件的函数使用
>>都是需要自己使用read、write、sendto、recv等函数按字节读取发送或者接收
>>
>>

论坛徽章:
0
3 [报告]
发表于 2007-03-03 00:53 |只看该作者
sendfile() 如何?还有 sendfile64(),好用不?

论坛徽章:
0
4 [报告]
发表于 2007-03-04 12:37 |只看该作者
原帖由 langue 于 2007-3-3 00:53 发表于 3楼  
sendfile() 如何?还有 sendfile64(),好用不?

>>
>>
>>应该可以使用,但是就怕不方便进行编码转换,例如asicc-->binary
>>我记得linux上常见的ftp程序是使用read、send类似的函数进行数据
>>发送,为的是方便进行编码转化
>>
>>
int
     sendfile(int fd, int s, off_t offset, size_t nbytes,
             struct sf_hdtr *hdtr, off_t *sbytes, int flags);

DESCRIPTION
     Sendfile() sends a regular file specified by descriptor fd out a stream
     socket specified by descriptor s.

     The offset argument specifies where to begin in the file.  The nbytes
     argument specifies how many bytes of the file should be sent, with 0 hav-
     ing the special meaning of send until the end of file has been reached.

     An optional header and/or trailer can be sent before and after the file
     data by specifying a pointer to a struct sf_hdtr, which has the following
     structure:

           struct sf_hdtr {
                   struct iovec *headers;  /* pointer to header iovecs */
                   int hdr_cnt;            /* number of header iovecs */
                   struct iovec *trailers; /* pointer to trailer iovecs */
                   int trl_cnt;            /* number of trailer iovecs */
           };

     The headers and trailers pointers, if non-NULL, point to arrays of struct
     iovec structures.  See the writev() system call for information on the
     iovec structure.  The number of iovecs in these arrays is specified by
     hdr_cnt and trl_cnt.

     If non-NULL, the system will write the total number of bytes sent on the
     socket to the variable pointed to by sbytes.

     The flags argument is currently undefined and should be specified as 0.

     When using a socket marked for non-blocking I/O, sendfile() may send
     fewer bytes than requested.  In this case, the number of bytes success-
     fully written is returned in *sbytes (if specified), and the error EAGAIN
     is returned.

论坛徽章:
0
5 [报告]
发表于 2007-03-06 15:28 |只看该作者

又有新问题了

用c写ftp上传一个文件夹下的所有文件至服务器的某一个文件夹下面,一个一个的上传,因为该文件夹下的文件是不断增加的,请问这种情况应该怎样实现,能不能给些思路或者应该用到的相关函数,谢谢了

论坛徽章:
0
6 [报告]
发表于 2007-03-15 09:24 |只看该作者
不要沉下去了,自己顶下

论坛徽章:
0
7 [报告]
发表于 2007-03-15 10:15 |只看该作者
我也知道如果要解决一个文件实时增加的文件夹下的文件上传,先统计当前文件夹的文件数,再发送到server,然后删除已上传文件到另一文件夹,如back,但是我感觉还是有问题,如果刚统计完,文件又增加了,那会不会出错呢,而且这种方法具体怎么实施呢?

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
8 [报告]
发表于 2007-03-16 06:47 |只看该作者
看CURL.

论坛徽章:
0
9 [报告]
发表于 2007-03-17 14:08 |只看该作者
sendfile 和ftp协议无关。无法上传ftp。
得先实现ftp协议
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP