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 27 by hirohitohigashi, Sat Feb 28 02:17:34 2009 UTC revision 29 by hirohitohigashi, Sat Feb 28 12:48:31 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  /****************************************************************************/  /****************************************************************************/
# Line 40  Line 39 
39   *@param        buf     バッファへのポインタ   *@param        buf     バッファへのポインタ
40   *@param        bufsiz  バッファサイズ   *@param        bufsiz  バッファサイズ
41   *@param        fname   サーバ上のファイル名   *@param        fname   サーバ上のファイル名
42     *@param        cmd     送信するFTPコマンド
43   *@retval       int     0: no error. -1: OS level error. -2: ftp protocol error. -3: buffer too small.   *@retval       int     0: no error. -1: OS level error. -2: ftp protocol error. -3: buffer too small.
44   *@note   *@note
45   */   */
46  int ftp_put_buffer( LIBOFTP *ftp, char *buf, int bufsiz, const char *fname )  static int ftp_put_buffer_main( LIBOFTP *ftp, char *buf, int bufsiz, const char *fname, const char *cmd )
47  {  {
48      int data_socket;      int data_socket;
49      char *p = buf;      char *p = buf;
50      int n;      int n, res;
51    
52      /*      /*
53       * 送信準備       * 送信準備
54       */       */
55      if( ftp->flag_passive ) {      if( ftp->flag_passive ) {
56          data_socket = ftp_getready_pasv( ftp, "STOR", fname );          data_socket = ftp_getready_pasv( ftp, cmd, fname );
57      } else {      } else {
58          data_socket = ftp_getready_active( ftp, "STOR", fname );          data_socket = ftp_getready_active( ftp, cmd, fname );
59      }      }
60      if( data_socket < 0 ) {      if( data_socket < 0 ) {
61          return data_socket;          return data_socket;
# Line 72  int ftp_put_buffer( LIBOFTP *ftp, char * Line 72  int ftp_put_buffer( LIBOFTP *ftp, char *
72          n = sendn( data_socket, p, len, 0 );          n = sendn( data_socket, p, len, 0 );
73          DEBUGPRINT1( "SEND: n=%d\n", n );          DEBUGPRINT1( "SEND: n=%d\n", n );
74          if( n < 0 ) {          if( n < 0 ) {
75                DEBUGPRINT1( "recv error. %s\n", strerror(errno) );
76                copy_strerror();
77              close( data_socket );              close( data_socket );
78              return -1;              return LIBOFTP_ERROR_OS;
         }  
         if( n == 0 ) {  
             break;  
79          }          }
80    
81          p += n;          p += n;
82          bufsiz -= n;          bufsiz -= n;
83          if( bufsiz <= 0 ) {          if( bufsiz <= 0 ) {
# Line 89  int ftp_put_buffer( LIBOFTP *ftp, char * Line 89  int ftp_put_buffer( LIBOFTP *ftp, char *
89      /*      /*
90       * receive response.       * receive response.
91       */       */
92      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 );
93          return -2;      if( res != 226 ) {                                          /* 226: Closing data connection. */
94            DEBUGPRINT1( "got illegal response %d\n", res );
95            return res < 0? res: LIBOFTP_ERROR_PROTOCOL;
96      }      }
97    
98      return 0;      return LIBOFTP_NOERROR;
99    }
100    
101    
102    
103    /***** Global functions *****************************************************/
104    
105    /****************************************************************************/
106    /*! バッファからファイル送信
107     *
108     *@param        ftp     LIBOFTPへのポインタ。
109     *@param        buf     バッファへのポインタ
110     *@param        bufsiz  バッファサイズ
111     *@param        fname   サーバ上のファイル名
112     *@retval       int     0: no error. -1: OS level error. -2: ftp protocol error. -3: buffer too small.
113     *@note
114     */
115    int ftp_put_buffer( LIBOFTP *ftp, char *buf, int bufsiz, const char *fname )
116    {
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     *@retval       int     0: no error. -1: OS level error. -2: ftp protocol error. -3: buffer too small.
130     *@note
131     */
132    int ftp_append_buffer( LIBOFTP *ftp, char *buf, int bufsiz, const char *fname )
133    {
134        return ftp_put_buffer_main( ftp, buf, bufsiz, fname, "APPE" );
135  }  }

Legend:
Removed from v.27  
changed lines
  Added in v.29

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