一个小程序,需要FTP功能,谁能给我提供一个Ftp Client的源码. 越小,功能简单实现全好...谢谢了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.vckbase.com/document/viewdoc/?id=1387 CString ServerXu="192.168.8.1"; CString message="网络服务器 "+ServerXu; CFtpConnection* connection=NULL; CInternetSession session; BOOL win; try { connection=session.GetFtpConnection(ServerXu,username, password,iPort,FALSE); } catch(CInternetException* pEx) { connection=NULL; pEx->Delete(); } if(!connection) { win=FALSE; message+="连接中断!请稍候再试。\r\n"; AfxMessageBox(message); return; } else win=TRUE; 谢谢cpio,青蛙.可以下文件就行了.. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample/html/_sample_mfc_ftptree.asp /*功能实现FTP封装作者:渊海作成日期:2005-09-26*/#include "FtpDll.h"#include "FtpBase.H"#include <windows.h>FTPEXPORT bool SetAccessRight(char *userName,char *userPass){ strcpy(FtpBase.ServerInfo.strPass,userPass); strcpy(FtpBase.ServerInfo.strUser,userName); if( !strcmp(FtpBase.ServerInfo.strPass,"") || !strcmp(FtpBase.ServerInfo.strUser,"")) return 0; return 1;}FTPEXPORT bool OpenConnection(char * server){ if(!strcmp(server,"")) return 0; strcpy(FtpBase.ServerInfo.strServerName,server); try { FtpBase.InternetSession = InternetOpen( "NEC FTP SERVER TO CLIENT", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); FtpBase.FtpConnection = InternetConnect( FtpBase.InternetSession, FtpBase.ServerInfo.strServerName , INTERNET_DEFAULT_FTP_PORT, FtpBase.ServerInfo.strUser , FtpBase.ServerInfo.strPass , INTERNET_SERVICE_FTP, 0, 0); } catch (CInternetException* pEx) { pEx->Delete(); return 0; } return 1;}FTPEXPORT bool CloseConnection(){ if(FtpBase.FtpConnection == NULL) return 0; try { InternetCloseHandle(FtpBase.InternetSession); InternetCloseHandle(FtpBase.FtpConnection); } catch(...) { return 0; } return 1;}FTPEXPORT bool PutFile(char * localFile, char * remoteFile){ BOOL bGotFile = FtpPutFile( FtpBase.FtpConnection, localFile, remoteFile, FTP_TRANSFER_TYPE_BINARY, NULL); return bGotFile ? 1 : 0 ;}FTPEXPORT bool GetFile(char * remoteFile,char * localFile){ BOOL bGotFile = FtpGetFile( FtpBase.FtpConnection, remoteFile, localFile, FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, NULL); return bGotFile ? 1 : 0 ;}FTPEXPORT bool RemoveFile(char * sFileName){ BOOL bGotFile = FtpDeleteFile(FtpBase.FtpConnection,sFileName); return bGotFile ? 1 : 0 ;}FTPEXPORT bool GetFTPDirectory(char * strDir){ DWORD dirlen=0; BOOL bGotFile = FtpGetCurrentDirectory( FtpBase.FtpConnection, strDir, &dirlen); return bGotFile ? 1 : 0 ;}FTPEXPORT bool SetFTPDirectory(char * strDir){ BOOL bGotFile = FtpSetCurrentDirectory( FtpBase.FtpConnection, strDir); return bGotFile ? 1 : 0 ;}FTPEXPORT HINTERNET OpenFile(char * strFile,int mode){ try { if(mode) FtpBase.FileConnt=FtpOpenFile( FtpBase.FtpConnection, strFile, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0); else FtpBase.FileConnt=FtpOpenFile( FtpBase.FtpConnection, strFile, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0); } catch(...) { return NULL; } return FtpBase.FileConnt;}FTPEXPORT bool WriteFile(HINTERNET hFile,char * buf){ DWORD buflen=0; BOOL bGotFile = InternetWriteFile(hFile, buf, strlen(buf), &buflen); return bGotFile ? 1 : 0 ;}FTPEXPORT bool ReadFile(HINTERNET hFile,char * buf){ DWORD buflen=0; BOOL bGotFile = InternetReadFile(hFile, buf, strlen(buf), &buflen); return bGotFile ? 1 : 0 ;}FTPEXPORT bool CloseFile(HINTERNET hFile){ try { InternetCloseHandle(hFile); } catch(...) { return 0; } return 1;} 如何在自定义类中使用View类中的函数?? odl文件内容问题? AnimateWindow函数问题,请教各位! 触发器的问题 求救,VC中使用Mysql 这道系统托盘程序是如何实现的? 借人气问道面试题目~~~~~~~~~~~~~~~~~!!! 请问空格和回车如何表示? 在VC++里(基于单文档)怎么屏蔽ALT+F4的消息 不能关联控件"Radio Button" 怎么在右键菜单中多添加一项实现相应的功能? VC.NET 和 C# 还有VC 处理数据量大一些程序的运行速度哪个快一些!!
CString message="网络服务器 "+ServerXu;
CFtpConnection* connection=NULL;
CInternetSession session;
BOOL win;
try
{
connection=session.GetFtpConnection(ServerXu,username,
password,iPort,FALSE);
}
catch(CInternetException* pEx)
{
connection=NULL;
pEx->Delete();
}
if(!connection)
{
win=FALSE;
message+="连接中断!请稍候再试。\r\n";
AfxMessageBox(message);
return;
}
else
win=TRUE;
功能实现FTP封装作者:渊海
作成日期:2005-09-26*/
#include "FtpDll.h"
#include "FtpBase.H"
#include <windows.h>FTPEXPORT bool SetAccessRight(char *userName,char *userPass)
{
strcpy(FtpBase.ServerInfo.strPass,userPass);
strcpy(FtpBase.ServerInfo.strUser,userName); if( !strcmp(FtpBase.ServerInfo.strPass,"") || !strcmp(FtpBase.ServerInfo.strUser,""))
return 0; return 1;
}FTPEXPORT bool OpenConnection(char * server)
{
if(!strcmp(server,""))
return 0; strcpy(FtpBase.ServerInfo.strServerName,server); try
{
FtpBase.InternetSession = InternetOpen(
"NEC FTP SERVER TO CLIENT",
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
0);
FtpBase.FtpConnection = InternetConnect(
FtpBase.InternetSession,
FtpBase.ServerInfo.strServerName ,
INTERNET_DEFAULT_FTP_PORT,
FtpBase.ServerInfo.strUser ,
FtpBase.ServerInfo.strPass ,
INTERNET_SERVICE_FTP,
0,
0); }
catch (CInternetException* pEx)
{
pEx->Delete();
return 0;
}
return 1;
}FTPEXPORT bool CloseConnection()
{
if(FtpBase.FtpConnection == NULL)
return 0; try
{
InternetCloseHandle(FtpBase.InternetSession);
InternetCloseHandle(FtpBase.FtpConnection);
}
catch(...)
{
return 0;
} return 1;
}FTPEXPORT bool PutFile(char * localFile, char * remoteFile)
{
BOOL bGotFile = FtpPutFile(
FtpBase.FtpConnection,
localFile,
remoteFile,
FTP_TRANSFER_TYPE_BINARY,
NULL);
return bGotFile ? 1 : 0 ;
}FTPEXPORT bool GetFile(char * remoteFile,char * localFile)
{
BOOL bGotFile = FtpGetFile(
FtpBase.FtpConnection,
remoteFile,
localFile,
FALSE,
FILE_ATTRIBUTE_NORMAL,
FTP_TRANSFER_TYPE_BINARY,
NULL);
return bGotFile ? 1 : 0 ;
}FTPEXPORT bool RemoveFile(char * sFileName)
{
BOOL bGotFile = FtpDeleteFile(FtpBase.FtpConnection,sFileName);
return bGotFile ? 1 : 0 ;
}
FTPEXPORT bool GetFTPDirectory(char * strDir)
{
DWORD dirlen=0; BOOL bGotFile = FtpGetCurrentDirectory(
FtpBase.FtpConnection,
strDir,
&dirlen); return bGotFile ? 1 : 0 ;
}FTPEXPORT bool SetFTPDirectory(char * strDir)
{
BOOL bGotFile = FtpSetCurrentDirectory(
FtpBase.FtpConnection,
strDir); return bGotFile ? 1 : 0 ;
}
FTPEXPORT HINTERNET OpenFile(char * strFile,int mode)
{
try
{
if(mode)
FtpBase.FileConnt=FtpOpenFile(
FtpBase.FtpConnection,
strFile,
GENERIC_WRITE,
FTP_TRANSFER_TYPE_BINARY,
0);
else
FtpBase.FileConnt=FtpOpenFile(
FtpBase.FtpConnection,
strFile,
GENERIC_READ,
FTP_TRANSFER_TYPE_BINARY,
0);
}
catch(...)
{
return NULL;
} return FtpBase.FileConnt;}
FTPEXPORT bool WriteFile(HINTERNET hFile,char * buf)
{
DWORD buflen=0; BOOL bGotFile = InternetWriteFile(hFile,
buf,
strlen(buf),
&buflen); return bGotFile ? 1 : 0 ;
}
FTPEXPORT bool ReadFile(HINTERNET hFile,char * buf)
{
DWORD buflen=0; BOOL bGotFile = InternetReadFile(hFile,
buf,
strlen(buf),
&buflen); return bGotFile ? 1 : 0 ;
}
FTPEXPORT bool CloseFile(HINTERNET hFile)
{
try
{
InternetCloseHandle(hFile);
}
catch(...)
{
return 0;
} return 1;
}