Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/ftp_pwd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (show annotations) (download) (as text)
Wed Feb 25 14:45:21 2009 UTC (15 years ago) by hirohitohigashi
File MIME type: text/x-csrc
File size: 2483 byte(s)
added pwd command.

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 <string.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 /*! PWD������������
32 *
33 *@param ftp LIBOFTP���������������������
34 *@param buf ���������������������������
35 *@param bufsiz ���������������������
36 *@retval int ������������������������������
37 *@note
38 */
39 int ftp_pwd( LIBOFTP *ftp, char *buf, int bufsiz )
40 {
41 char str1[512] = "PWD\r\n";
42 int ret;
43 char *p1, *p2;
44
45 /*
46 * send PWD command
47 */
48 if( sendn( ftp->socket, str1, strlen( str1 ), 0 ) < 0 ) {
49 DEBUGPRINT1( "pwd: command sending error. %s\n", str1 );
50 return -1;
51 }
52
53 if( (ret = ftp_receive_response( ftp, str1, sizeof(str1) )) != 257 ) { /* 257: "PATHNAME" created. */
54 DEBUGPRINT1( "pwd: command response error. %d\n", ret );
55 return -2;
56 }
57
58 /*
59 * parse response
60 */
61 p1 = strchr( str1, '"' );
62 if( p1 == NULL ) {
63 DEBUGPRINT1( "pwd: reply string parse error. %s\n", str1 );
64 return -2;
65 }
66
67 p2 = strchr( p1+1, '"' );
68 if( p2 == NULL ) {
69 DEBUGPRINT1( "pwd: reply string parse error. %s\n", str1 );
70 return -2;
71 }
72 if( bufsiz < (p2-p1) ) {
73 DEBUGPRINT1( "pwd: buffer too small.%s", "" );
74 return -3;
75 }
76
77 memcpy( buf, p1+1, p2 - p1 - 1 );
78 buf[ p2 - p1 - 1 ] = 0;
79
80 return 0;
81 }

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