Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /tags/REL-2.1/ftp_put_buffer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (hide annotations) (download) (as text)
Sun Mar 8 07:32:44 2009 UTC (15 years, 1 month ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 4056 byte(s)
Tag release 2.1
1 hirohitohigashi 17 /*
2     liboftp: this is an FTP library to simplify the work to a Developer
3     who want to work with FTP servers (RFC 959).
4    
5     Copyright (c) 2009 hirohito higashi. All rights reserved.
6     This file is distributed under BSD license.
7     */
8    
9    
10     /***** Feature test switches ************************************************/
11     /***** System headers *******************************************************/
12     #include <unistd.h>
13     #include <sys/types.h>
14     #include <sys/socket.h>
15    
16    
17     /***** Local headers ********************************************************/
18     #include "liboftp.h"
19     #include "sub.h"
20    
21    
22     /***** Constat values *******************************************************/
23     #define TRANSFER_SEGMENT_SIZE 4096 /* 一度のrecv()で転送するバイト数 */
24    
25    
26     /***** Macros ***************************************************************/
27     /***** Typedefs *************************************************************/
28     /***** Function prototypes **************************************************/
29     /***** Local variables ******************************************************/
30     /***** Global variables *****************************************************/
31     /***** Signal catching functions ********************************************/
32     /***** Local functions ******************************************************/
33    
34    
35     /****************************************************************************/
36     /*! バッファからファイル送信
37     *
38     *@param ftp LIBOFTPへのポインタ。
39     *@param buf バッファへのポインタ
40     *@param bufsiz バッファサイズ
41 hirohitohigashi 27 *@param fname サーバ上のファイル名
42 hirohitohigashi 28 *@param cmd 送信するFTPコマンド
43 hirohitohigashi 30 *@retval int エラーコード
44 hirohitohigashi 17 *@note
45     */
46 hirohitohigashi 45 static int ftp_put_buffer_main( LIBOFTP *ftp, const char *buf, int bufsiz, const char *fname, const char *cmd )
47 hirohitohigashi 17 {
48     int data_socket;
49 hirohitohigashi 45 const char *p = buf;
50 hirohitohigashi 29 int n, res;
51 hirohitohigashi 17
52     /*
53     * 送信準備
54     */
55     if( ftp->flag_passive ) {
56 hirohitohigashi 28 data_socket = ftp_getready_pasv( ftp, cmd, fname );
57 hirohitohigashi 17 } else {
58 hirohitohigashi 28 data_socket = ftp_getready_active( ftp, cmd, fname );
59 hirohitohigashi 17 }
60 hirohitohigashi 20 if( data_socket < 0 ) {
61     return data_socket;
62     }
63 hirohitohigashi 17
64     /*
65     * タイムアウトが意図通りに働くように、分割してsendする。
66     */
67     while( 1 ) {
68     int len = bufsiz;
69     if( len > TRANSFER_SEGMENT_SIZE ) {
70     len = TRANSFER_SEGMENT_SIZE;
71     }
72     n = sendn( data_socket, p, len, 0 );
73     DEBUGPRINT1( "SEND: n=%d\n", n );
74     if( n < 0 ) {
75 hirohitohigashi 29 DEBUGPRINT1( "recv error. %s\n", strerror(errno) );
76     copy_strerror();
77 hirohitohigashi 17 close( data_socket );
78 hirohitohigashi 29 return LIBOFTP_ERROR_OS;
79 hirohitohigashi 17 }
80 hirohitohigashi 28
81 hirohitohigashi 17 p += n;
82     bufsiz -= n;
83     if( bufsiz <= 0 ) {
84     break;
85     }
86     }
87     close( data_socket );
88    
89     /*
90     * receive response.
91     */
92 hirohitohigashi 29 res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message)-1 );
93     if( res != 226 ) { /* 226: Closing data connection. */
94     DEBUGPRINT1( "got illegal response %d\n", res );
95     return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
96 hirohitohigashi 17 }
97    
98 hirohitohigashi 29 return LIBOFTP_NOERROR;
99 hirohitohigashi 17 }
100 hirohitohigashi 28
101    
102    
103     /***** Global functions *****************************************************/
104    
105     /****************************************************************************/
106     /*! バッファからファイル送信
107     *
108     *@param ftp LIBOFTPへのポインタ。
109     *@param buf バッファへのポインタ
110     *@param bufsiz バッファサイズ
111     *@param fname サーバ上のファイル名
112 hirohitohigashi 30 *@retval int エラーコード
113 hirohitohigashi 28 *@note
114     */
115 hirohitohigashi 45 int ftp_put_buffer( LIBOFTP *ftp, const char *buf, int bufsiz, const char *fname )
116 hirohitohigashi 28 {
117     return ftp_put_buffer_main( ftp, buf, bufsiz, fname, "STOR" );
118     }
119    
120    
121    
122     /****************************************************************************/
123     /*! バッファからファイル送信 アペンドモード
124     *
125     *@param ftp LIBOFTPへのポインタ。
126     *@param buf バッファへのポインタ
127     *@param bufsiz バッファサイズ
128     *@param fname サーバ上のファイル名
129 hirohitohigashi 30 *@retval int エラーコード
130 hirohitohigashi 28 *@note
131     */
132 hirohitohigashi 45 int ftp_append_buffer( LIBOFTP *ftp, const char *buf, int bufsiz, const char *fname )
133 hirohitohigashi 28 {
134     return ftp_put_buffer_main( ftp, buf, bufsiz, fname, "APPE" );
135     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26