| 1 |
hirohitohigashi |
24 |
/* |
| 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 |
hirohitohigashi |
30 |
*@retval int ������������������ |
| 37 |
hirohitohigashi |
24 |
*@note |
| 38 |
|
|
*/ |
| 39 |
|
|
int ftp_rename( LIBOFTP *ftp, const char *from, const char *to ) |
| 40 |
|
|
{ |
| 41 |
|
|
char str1[512]; |
| 42 |
hirohitohigashi |
29 |
int res; |
| 43 |
hirohitohigashi |
24 |
|
| 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 |
hirohitohigashi |
29 |
DEBUGPRINT1( "RNFR command sending error. %s\n", str1 ); |
| 50 |
|
|
return LIBOFTP_ERROR_OS; |
| 51 |
hirohitohigashi |
24 |
} |
| 52 |
|
|
|
| 53 |
hirohitohigashi |
29 |
res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message)-1 ); |
| 54 |
|
|
if( res != 350 ) { /* 350: Requested file action pending further information */ |
| 55 |
|
|
DEBUGPRINT1( "RNFR command response error. %d\n", res ); |
| 56 |
|
|
return res < 0? res: LIBOFTP_ERROR_PROTOCOL; |
| 57 |
hirohitohigashi |
24 |
} |
| 58 |
|
|
|
| 59 |
|
|
/* |
| 60 |
|
|
* send RNTO command |
| 61 |
|
|
*/ |
| 62 |
|
|
snprintf( str1, sizeof(str1)-1, "RNTO %s\r\n", to ); |
| 63 |
|
|
if( ftp_send_command( ftp, str1 ) < 0 ) { |
| 64 |
|
|
DEBUGPRINT1( "rename: RNTO command sending error. %s\n", str1 ); |
| 65 |
hirohitohigashi |
29 |
return LIBOFTP_ERROR_OS; |
| 66 |
hirohitohigashi |
24 |
} |
| 67 |
|
|
|
| 68 |
hirohitohigashi |
29 |
res = ftp_receive_response( ftp, ftp->error_message, sizeof(ftp->error_message)-1 ); |
| 69 |
|
|
if( res != 250 ) { /* 250: Requested file action okay, completed. */ |
| 70 |
|
|
DEBUGPRINT1( "RNTO command response error. %d\n", res ); |
| 71 |
|
|
return res < 0? res: LIBOFTP_ERROR_PROTOCOL; |
| 72 |
hirohitohigashi |
24 |
} |
| 73 |
|
|
|
| 74 |
hirohitohigashi |
29 |
return LIBOFTP_NOERROR; |
| 75 |
hirohitohigashi |
24 |
} |