FTP_transfer/query.cpp
2024-09-12 18:17:01 +08:00

41 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 此程序演示采用开发框架的cftpclient类获取ftp服务器上的文件列表、时间和大小。
*/
#include "_ftp.h"
using namespace eviwbh;
int main(int argc,char *argv[])
{
cftpclient ftp;
// 登录远程ftp服务器请改为你自己服务器的ip地址。
if (ftp.login("127.0.0.1:21","eviwbh","password") == false)
{
printf("ftp.login(127.0.0.1:21,eviwbh/password) failed.\n"); return -1;
}
// 获取服务器上/project/public/*.h文件列表保存在本地的/tmp/list/tmp.list文件中。
// 如果/tmp/list目录不存在会自动创建它。
if (ftp.nlist("/project/public/*.h","/tmp/list/tmp.list")==false)
{
printf("ftp.nlist() failed.\n"); return -1;
}
cout << "ret=" << ftp.response() << endl;
cifile ifile; // 采用开发框架的cifile类来操作list文件。
string strFileName;
ifile.open("/tmp/list/tmp.list"); // 打开list文件。
while(true) // 获取每个文件的时间和大小。
{
if (ifile.readline(strFileName)==false) break;
ftp.mtime(strFileName); // 获取文件时间。
ftp.size(strFileName); // 获取文件大小。
printf("filename=%s,mtime=%s,size=%d\n",strFileName.c_str(),ftp.m_mtime.c_str(),ftp.m_size);
}
}