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