Develop and Download Open Source Software

Browse Subversion Repository

Contents of /tags/REL-2.2/ftp_rename.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (show annotations) (download) (as text)
Sat Feb 28 00:57:58 2009 UTC (15 years, 1 month ago) by hirohitohigashi
Original Path: trunk/ftp_rename.c
File MIME type: text/x-csrc
File size: 2531 byte(s)
added file rename function.

1 /*
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 <stdio.h>
13
14
15 /***** Local headers ********************************************************/
16 #include "liboftp.h"
17 #include "sub.h"
18
19
20 /***** Constat values *******************************************************/
21 /***** Macros ***************************************************************/
22 /***** Typedefs *************************************************************/
23 /***** Function prototypes **************************************************/
24 /***** Local variables ******************************************************/
25 /***** Global variables *****************************************************/
26 /***** Signal catching functions ********************************************/
27 /***** Local functions ******************************************************/
28 /***** Global functions *****************************************************/
29
30 /****************************************************************************/
31 /*! ������������������������
32 *
33 *@param ftp LIBOFTP���������������������
34 *@param from ���������������������
35 *@param to ������������������������
36 *@retval int ������������������������������
37 *@note
38 */
39 int ftp_rename( LIBOFTP *ftp, const char *from, const char *to )
40 {
41 char str1[512];
42 int ret;
43
44 /*
45 * send RNFR command
46 */
47 snprintf( str1, sizeof(str1)-1, "RNFR %s\r\n", from );
48 if( ftp_send_command( ftp, str1 ) < 0 ) {
49 DEBUGPRINT1( "rename: RNFR command sending error. %s\n", str1 );
50 return -1;
51 }
52
53 if( (ret = ftp_receive_response( ftp, str1, sizeof(str1) )) != 350 ) { /* 350: Requested file action pending further information */
54 DEBUGPRINT1( "rename: RNFR command response error. %d\n", ret );
55 return -2;
56 }
57
58 /*
59 * send RNTO command
60 */
61 snprintf( str1, sizeof(str1)-1, "RNTO %s\r\n", to );
62 if( ftp_send_command( ftp, str1 ) < 0 ) {
63 DEBUGPRINT1( "rename: RNTO command sending error. %s\n", str1 );
64 return -1;
65 }
66
67 if( (ret = ftp_receive_response( ftp, str1, sizeof(str1) )) != 250 ) { /* 250: Requested file action okay, completed. */
68 DEBUGPRINT1( "rename: RNTO command response error. %d\n", ret );
69 return -2;
70 }
71
72 return 0;
73 }

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