c++ ftp上传下载
#include <afxinet.h>
int main()
{
BOOL dRes,pRes;
HINTERNET hInternet;
HINTERNET hConnect;
hInternet = InternetOpen("A3GS Sample", INTERNET_OPEN_TYPE_DIRECT,NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE);
if ( NULL == hInternet )
{
printf("InternetOpen Error:%d\n", GetLastError() );
}
hConnect = InternetConnect(hInternet, "192.168.1.225"/*FTP服务器地址*/, INTERNET_DEFAULT_FTP_PORT/*FTP端口号,此为默认值---21*/,"admin"/*用户名*/, "admin"/*密码*/, INTERNET_SERVICE_FTP, INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 );
if ( NULL == hInternet )
{
printf( "InternetConnect Error:%d\n", GetLastError() );
InternetCloseHandle(hInternet);
}
//文件上传
pRes = FtpPutFile(hConnect,"D:\\FTP\\测试文本.txt","./zwh/测试文本.txt",FTP_TRANSFER_TYPE_ASCII,0);
if(pRes==0)
{
printf("上传文件失败!\n");
}
else
{
printf("上传文件成功!\n");
}
//文件下载
dRes = FtpGetFile(hConnect, "./zwh/测试文本.txt", "D:\\FTP\\测试文本副本.txt", FALSE, FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_UNKNOWN, 0);
if ( dRes == 0 )
{
printf( "FtpGetFile Error:\n", GetLastError() );
}
else
{
printf( "下载文件成功!\n" );
}
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
if(dRes&&pRes)
return true;
else
return false;
}