2016-01-05 19:46:22|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, 网络通信|来源:唯设编程网
int CFTP::ftp_pwd( char* buff ) { sprintf_s(m_cmd,"PWD "); int err = ftp_sendcmd(m_cmd,m_resp,sizeof(m_resp)); if(err) return -1; //得到返回码 int code = get_state_code(m_resp); //257 "/" is current directory. /* 550-The system cannot find the file specified. Win32 error: The system cannot find the file specified. Error details: File system returned an error. 550 End */ if(code != 257) return -1; char* p=m_resp; while(*p) { if(*p == '"'){ ++p; while(*p != '"') *buff++=*p++; } ++p; } *buff=0; printf("current work directory is : %s ",buff); return 0; }
使用PWD命令获取当前所在的FTP目录,如果返回码是257,表示命令执行成功,再使用recv函数获取字符串形式的ftp目录。
int CFTP::ftp_mkdirSingle( const char* dir ) { sprintf_s(m_cmd,"MKD %s ",dir); int err = ftp_sendcmd(m_cmd,m_resp,sizeof(m_resp)); if(err) return -1; //得到返回码 int code = get_state_code(m_resp); //257 "20150110" directory created. if(code != 257) return -1; return 0; }
使用MKD命令创建文件夹,创建成功的返回码是257。