由于经常要到一个固定ftp下载几个文件,不想每次都重复登陆选择,因此用C写了一个简单的ftp自动下载程序。
从FTP 134.101.50.23/Mapper/CDMA/ 目录下下载命名以CDMA开始的文件到本地地址。
源代码如下:
#include <afx.h>
#include <afxwin.h>
#include <afxinet.h>
#include <stdio.h>
CWinApp theApp;
void main()
{
int iFileCnt =0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
return;
}
// create a session object to initialize WININET library
CInternetSession sess(_T("MyProgram/1.0"));
CFtpConnection* pConnect = NULL;
try
{
// Request a connection to ftp Default with username = ANONYMOUS
// and password set to the machine name @ domain name
pConnect = sess.GetFtpConnection(_T("134.101.50.23"));
// use a file find object to find files
CFtpFileFind find