如何用C++实现FTP文件上传的程序
展开全部
给你个例子
#include <afxinet.h>
void 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, "127.0.0.1", INTERNET_DEFAULT_FTP_PORT,
"ww123", "12345", INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 );
if ( NULL == hInternet )
{
printf( "InternetConnect Error:%d\n", GetLastError() );
InternetCloseHandle(hInternet);
}
dRes = FtpGetFile(hConnect, "./wwyy/download/test1.txt", "D:\\BT\\test1.txt", FALSE,
FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_UNKNOWN, 0);
if ( dRes == 0 )
{
printf( "FtpGetFile Error:\n", GetLastError() );
}else{
printf( "下载文件成功!\n" );
}
pRes = FtpPutFile(hConnect,"D:\\BT\\hhsj.txt","hhsj.txt",FTP_TRANSFER_TYPE_ASCII,0);
if(pRes==0)
{
printf("上传文件失败!\n");
}else{
printf("上传文件成功!\n");
}
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
if(dRes&&pRes) return true;
else return false;
#include <afxinet.h>
void 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, "127.0.0.1", INTERNET_DEFAULT_FTP_PORT,
"ww123", "12345", INTERNET_SERVICE_FTP,
INTERNET_FLAG_EXISTING_CONNECT || INTERNET_FLAG_PASSIVE,0 );
if ( NULL == hInternet )
{
printf( "InternetConnect Error:%d\n", GetLastError() );
InternetCloseHandle(hInternet);
}
dRes = FtpGetFile(hConnect, "./wwyy/download/test1.txt", "D:\\BT\\test1.txt", FALSE,
FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_UNKNOWN, 0);
if ( dRes == 0 )
{
printf( "FtpGetFile Error:\n", GetLastError() );
}else{
printf( "下载文件成功!\n" );
}
pRes = FtpPutFile(hConnect,"D:\\BT\\hhsj.txt","hhsj.txt",FTP_TRANSFER_TYPE_ASCII,0);
if(pRes==0)
{
printf("上传文件失败!\n");
}else{
printf("上传文件成功!\n");
}
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
if(dRes&&pRes) return true;
else return false;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询