Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/ftp_put_buffer.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 17 by hirohitohigashi, Wed Feb 25 13:47:38 2009 UTC revision 50 by hirohitohigashi, Wed Dec 2 15:13:30 2009 UTC
# Line 30  Line 30 
30  /***** Global variables *****************************************************/  /***** Global variables *****************************************************/
31  /***** Signal catching functions ********************************************/  /***** Signal catching functions ********************************************/
32  /***** Local functions ******************************************************/  /***** Local functions ******************************************************/
 /***** Global functions *****************************************************/  
33    
34    
35  /****************************************************************************/  /****************************************************************************/
36  /*! バッファからファイル送信  /*! バッファからファイル送信
37   *   *
38   *@param        ftp     LIBOFTPへのポインタ。   *@param        ftp     LIBOFTPへのポインタ。
  *@param        fname   サーバ上のファイル名  
39   *@param        buf     バッファへのポインタ   *@param        buf     バッファへのポインタ
40   *@param        bufsiz  バッファサイズ   *@param        bufsiz  バッファサイズ
41   *@retval       int     0: no error. -1: OS level error. -2: ftp protocol error. -3: buffer too small.   *@param        fname   サーバ上のファイル名
42     *@param        cmd     送信するFTPコマンド
43     *@retval       int     エラーコード
44   *@note   *@note
45   */   */
46  int ftp_put_buffer( LIBOFTP *ftp, const char *fname, char *buf, int bufsiz )  static int ftp_put_buffer_main( LIBOFTP *ftp, const char *buf, int bufsiz, const char *fname, const char *cmd )
47  {  {
48      int data_socket;      int data_socket;
49      char *p = buf;      const char *p = buf;
50      int n;      int n, res;
51    
52        if( ftp->socket < 0 ) return LIBOFTP_ERROR;
53    
54      /*      /*
55       * 送信準備       * 送信準備
56       */       */
57      if( ftp->flag_passive ) {      if( ftp->flag_passive ) {
58          data_socket = ftp_getready_pasv( ftp, fname, "STOR" );          data_socket = ftp_getready_pasv( ftp, cmd, fname );
         if( data_socket < 0 ) {  
             return -1;          /* XXX: mixed os level error and ftp protocol error. */  
         }  
59      } else {      } else {
60          return -2;              /* XXX: active mode not ready yet. */          data_socket = ftp_getready_active( ftp, cmd, fname );
61        }
62        if( data_socket < 0 ) {
63            return data_socket;
64      }      }
65    
66      /*      /*
# Line 72  int ftp_put_buffer( LIBOFTP *ftp, const Line 74  int ftp_put_buffer( LIBOFTP *ftp, const
74          n = sendn( data_socket, p, len, 0 );          n = sendn( data_socket, p, len, 0 );
75          DEBUGPRINT1( "SEND: n=%d\n", n );          DEBUGPRINT1( "SEND: n=%d\n", n );
76          if( n < 0 ) {          if( n < 0 ) {
77                DEBUGPRINT1( "recv error. %s\n", strerror(errno) );
78                copy_strerror();
79              close( data_socket );              close( data_socket );
80              return -1;              return LIBOFTP_ERROR_OS;
         }  
         if( n == 0 ) {  
             break;  
81          }          }
82    
83          p += n;          p += n;
84          bufsiz -= n;          bufsiz -= n;
85          if( bufsiz <= 0 ) {          if( bufsiz <= 0 ) {
# Line 89  int ftp_put_buffer( LIBOFTP *ftp, const Line 91  int ftp_put_buffer( LIBOFTP *ftp, const
91      /*      /*
92       * receive response.       * receive response.
93       */       */
94      if( ftp_receive_response( ftp, 0, 0 ) != 226 ) {    /* 226: Closing data connection. */      res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message)-1 );
95          return -2;      if( res != 226 ) {                                          /* 226: Closing data connection. */
96            DEBUGPRINT1( "got illegal response %d\n", res );
97            return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
98      }      }
99    
100      return 0;      return LIBOFTP_NOERROR;
101    }
102    
103    
104    
105    /***** Global functions *****************************************************/
106    
107    /****************************************************************************/
108    /*! バッファからファイル送信
109     *
110     *@param        ftp     LIBOFTPへのポインタ。
111     *@param        buf     バッファへのポインタ
112     *@param        bufsiz  バッファサイズ
113     *@param        fname   サーバ上のファイル名
114     *@retval       int     エラーコード
115     *@note
116     */
117    int ftp_put_buffer( LIBOFTP *ftp, const char *buf, int bufsiz, const char *fname )
118    {
119        return ftp_put_buffer_main( ftp, buf, bufsiz, fname, "STOR" );
120    }
121    
122    
123    
124    /****************************************************************************/
125    /*! バッファからファイル送信 アペンドモード
126     *
127     *@param        ftp     LIBOFTPへのポインタ。
128     *@param        buf     バッファへのポインタ
129     *@param        bufsiz  バッファサイズ
130     *@param        fname   サーバ上のファイル名
131     *@retval       int     エラーコード
132     *@note
133     */
134    int ftp_append_buffer( LIBOFTP *ftp, const char *buf, int bufsiz, const char *fname )
135    {
136        return ftp_put_buffer_main( ftp, buf, bufsiz, fname, "APPE" );
137  }  }

Legend:
Removed from v.17  
changed lines
  Added in v.50

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