1.网游运行中的崩溃异常 etc 需要搜集上传到运营商的服务器上,以便解决问题。
2.在此提供一个FTP上传类。
3.当然上传的文件内容,不容我多说,是程序员自己定义的各种dump日志。
#pragma once
#include <string>
#include <afxinet.h>
using namespace std;
class ZBugZiller
{
public:
ZBugZiller();
~ZBugZiller();
void Release();
void SetFTPInfo(const string & serverAddress, const int & portNumber = 21);
void SetAccount (const string & strUserID, const string & strUserPassword);
void ConnectFTP();
void Upload(char * strlocalFile, char * strRemoteFile);
private:
string m_userID;
string m_userPassword;
string m_strServerAddress;
int m_iPortNo;
private: // MFC classes
CInternetSession * m_pSession;
CFtpConnection * m_pFtpConnection;
};
#include "StdAfx.h"
#include ".\zbugziller.h"
#include <IO.H>
ZBugZiller::ZBugZiller()
{
m_userID = "";
m_userPassword = "";
m_strServerAddress = "";
m_iPortNo = 21;
m_pSession = NULL;
m_pFtpConnection = NULL;
}
void ZBugZiller::SetFTPInfo(const string & serverAddress, const int & portNumber)
{
m_strServerAddress = serverAddress;
m_iPortNo = portNumber;
}
void ZBugZiller::SetAccount (const string & strUserID, const string & strUserPassword)
{
m_userID = strUserID;
m_userPassword = strUserPassword;
}
void ZBugZiller::ConnectFTP()
{
m_pSession = new CInternetSession();
try
{
m_pFtpConnection = m_pSession->GetFtpConnection(m_strServerAddress.c_str(), m_userID.c_str(), m_userPassword.c_str(), m_iPortNo, TRUE);
}
catch ( ... )
{
Release();
// MessageBox(HWND_DESKTOP, "[坷幅] : 辑滚俊 立加 且 荐 绝嚼聪促.", "宫氢柯扼牢", MB_OK);
return;
}
}
void ZBugZiller::Release()
{
if ( m_pFtpConnection != NULL )
{
m_pFtpConnection->Close();
delete m_pFtpConnection;
m_pFtpConnection =NULL;
}
if ( m_pSession != NULL )
{
m_pSession->Close();
delete m_pSession;
m_pSession =NULL;
}
}
ZBugZiller::~ZBugZiller(void)
{
Release();
}
void ZBugZiller::Upload(char * strlocalFile, char * strRemoteFile)
{
if(!m_pFtpConnection || !m_pSession)
return;
// CFileStatus aStatus;
//if ( CFile::GetStatus(strlocalFile, aStatus) == TRUE )
// {
/*
CTime creationTime = aStatus.m_ctime;
CString strTime = "[";
strTime += strKey.c_str();
strTime += "]";
strTime += creationTime.Format("(%Y-%m-%d)%H-%M-%S");
*/
//CString strTime;
if( _access(strlocalFile, 0) != -1)
{
try
{
m_pFtpConnection->PutFile(strlocalFile, strRemoteFile, FTP_TRANSFER_TYPE_ASCII);
}
catch ( ... )
{
Release();
// MessageBox(HWND_DESKTOP, "[坷幅] : 辑滚俊 肺弊甫 傈崔 且 荐 绝嚼聪促.", "宫氢柯扼牢", MB_OK);
return;
}
while(1)
{
if(DeleteFile(strlocalFile) == TRUE)
break;
Sleep(200);
}
}
// }
}