⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftpconnection.cpp

📁 MFC 函数实用手册 MFC 函数实用手册
💻 CPP
字号:
// FtpConnection.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "FtpConnection.h"
#include <afxinet.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 唯一的应用程序对象

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// 初始化 MFC 并在失败时显示错误
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: 更改错误代码以符合您的需要
		_tprintf(_T("致命错误:MFC 初始化失败\n"));
		nRetCode = 1;
	}
	else
	{
		// TODO: 在此处为应用程序的行为编写代码。
	
	//	=========== CFtpFindFile

		CInternetSession* pInetSesn = new CInternetSession();
		CFtpConnection* pConn = NULL;
		try
		{
			CInternetFile* pCmdSuccess = NULL;
			pConn = pInetSesn->GetFtpConnection( _T("202.38.242.29"),NULL, NULL, 7626 );
			if( pConn != NULL )
			{
				CFtpFileFind ftpf(pConn);
				BOOL bSucc = ftpf.FindFile("*");
				while( bSucc )
				{
					bSucc = ftpf.FindNextFile();
					cout << (LPCTSTR)ftpf.GetFileName() << endl;
				}
			}
			cout << "\ncommand successed." <<endl;
		}
		catch(CInternetException* pEx)
		{
			pEx->ReportError();
			pEx->Delete();
		}
	
		//CInternetSession* pInetSesn = new CInternetSession();
		try
		{
			CFtpConnection* pftp = new CFtpConnection(pInetSesn, _T("202.38.242.29"),
														NULL, NULL, 0, 7626);
			//pftp->Command("CWD /");
			//pftp->Command("Get");
			//pftp->SetCurrentDirectory("/");
			//pftp->CreateDirectory("mydir");
			// GetCurrentDirectory
			/*
			CString szDir;
			pftp->GetCurrentDirectory(szDir);
			pftp->Close();
			cout << "Current Directory is " << (LPCTSTR)szDir << "." << endl;
			cout << "Command successed." <<endl;
			*/
			
			// get && put file
			
			//if( /*pftp->GetFile("cs.swf","C:\\cs.swf")*/ pftp->PutFile("G:\\FLASH\\cs.swf", "hahahah.swf") )
			/*	cout << "Command successed." << endl;
			else
			{
				DWORD dw = GetLastError();
				CHAR szBuf[80]; 
				sprintf(szBuf, "GetLastError returned %u.", dw);
				cout << szBuf << endl;
			}
			*/
		
			//if( /*pftp->RemoveDirectory("mydir")*/ pftp->Rename("five.mid","four.mid") )
			/*	cout << "Command successed." << endl;
			else
			{
				DWORD dw = GetLastError();
				CHAR szBuf[80]; 
				sprintf(szBuf, "GetLastError returned %u.", dw);
				cout << szBuf << endl;
			}*/
	
			/*
			if ( !pftp->SetCurrentDirectory("FLASH\\") )
			{
				cout << "abc" << endl;
				DWORD dw = GetLastError();
				CHAR szBuf[80]; 
				sprintf(szBuf, "GetLastError returned %u.", dw);
				cout << szBuf << endl;
			}
			CString szURL;
			pftp->GetCurrentDirectoryAsURL(szURL);
			cout << "URL is " << (LPCTSTR)szURL << endl;*/

			if( pftp->SetCurrentDirectory("game") )
			{
				cout << "Openning file..." << endl;
				CInternetFile* pInetFile = pftp->OpenFile("solaris.exe");
				byte buf(255);
				pInetFile->Read( &buf, sizeof(buf) );
			}
			pftp->Close();
		}
		catch(CInternetException* pEx)
		{
			pEx->ReportError();
			pEx->Delete();
		}
	}
	getchar();
	return nRetCode;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -