当前位置: 首页>>代码示例>>C++>>正文


C++ CInternetSession::GetFtpConnection方法代码示例

本文整理汇总了C++中CInternetSession::GetFtpConnection方法的典型用法代码示例。如果您正苦于以下问题:C++ CInternetSession::GetFtpConnection方法的具体用法?C++ CInternetSession::GetFtpConnection怎么用?C++ CInternetSession::GetFtpConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CInternetSession的用法示例。


在下文中一共展示了CInternetSession::GetFtpConnection方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sendFileThread

DWORD WINAPI sendFileThread(LPVOID lpParam)
{
	char *filename = (char *)lpParam;
	try
	{
		char installPath[1024];
		CModuleUtil::getInstallPath(installPath);

		char fname[1024];
		sprintf(fname, "%s\\%s", installPath, filename);
		char fnameGz[1024];
		sprintf(fnameGz, "%s\\%s.gz", installPath, filename);
		char remoteFileName[128];
		sprintf(remoteFileName, "incoming/%s-%d-%d.gz", filename, time(NULL), rand());
		file_compress(fname, "wb");
		CInternetSession session;
		CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "[email protected]", 21, true);
		ftpConnection->PutFile(fnameGz, remoteFileName);
		ftpConnection->Close();
		delete ftpConnection;


		_unlink(fname);
		_unlink(fnameGz);

		fileSendingProgress = 1;
	}
	catch (CInternetException*)
	{
		fileSendingProgress = -1;
	}
	return 0;
}
开发者ID:ArthurRTz,项目名称:tibiaauto,代码行数:33,代码来源:OptionsDialog.cpp

示例2: PutFile

BOOL CFtpFileDlg::PutFile( CString strSourceName,CString strDesName )
{
	CInternetSession* pSession;
	CFtpConnection *pConnection;
	pConnection = NULL;
	pSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
	try{
		pConnection = pSession->GetFtpConnection(m_strFtpSite,m_strName,m_strPwd);
	}
	catch(CInternetException *e){
		e->Delete();
		pConnection = NULL;
		return FALSE;
	}
	if(pConnection != NULL){
		if (!pConnection->PutFile(strSourceName,strDesName)){
			pConnection->Close();
			delete pConnection;
			delete pSession;
			return FALSE;
		}
	}
	if (pConnection != NULL){
		pConnection->Close();
		delete pConnection;
	}
	delete pSession;
	return TRUE;
}
开发者ID:zzzbit,项目名称:FtpFile,代码行数:29,代码来源:FtpFileDlg.cpp

示例3: ListContent

void CFtpFileDlg::ListContent()
{
	CInternetSession* pSession;
	CFtpConnection* pConnection;
	CFtpFileFind* pFileFind;
	CString strFileName;
	BOOL bContinue;
	pConnection = NULL;
	pFileFind = NULL;
	pSession = new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
	try{
		pConnection = pSession->GetFtpConnection(m_strFtpSite,m_strName,m_strPwd);
	}
	catch(CInternetException *e){
		e->Delete();
		pConnection = NULL;
		AfxMessageBox("连接失败!",MB_OK|MB_ICONSTOP);
	}
	if (pConnection!= NULL){
		pFileFind = new CFtpFileFind(pConnection);
		bContinue = pFileFind->FindFile(NULL);
		if (!bContinue){
			pFileFind->Close();
			pFileFind=NULL;
		}
		while(bContinue){
			bContinue = pFileFind->FindNextFile();
			strFileName = pFileFind->GetFileName();
			if (pFileFind->IsDirectory())
			{
				strFileName = "["+strFileName;
				strFileName += "]";
			}
			m_ListFile.AddString(strFileName);
		}
		if (pFileFind!=NULL){
			pFileFind->Close();
			pFileFind=NULL;
		}
	}
	delete pFileFind;
	if (pConnection!=NULL){
		pConnection->Close();
		delete pConnection;
	}
	delete pSession;
}
开发者ID:zzzbit,项目名称:FtpFile,代码行数:47,代码来源:FtpFileDlg.cpp

示例4: sendMapsThread

DWORD WINAPI sendMapsThread(LPVOID lpParam)
{
	char *path = (char *)lpParam;

	try
	{
		char fullMask[1024];
		sprintf(fullMask, "%s\\*.map", path);
		WIN32_FIND_DATA data;
		HANDLE hFind = FindFirstFile(fullMask, &data);
		if (hFind != INVALID_HANDLE_VALUE)
		{
			CInternetSession session;
			CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "[email protected]", 21, true);
			time_t t                      = time(NULL);
			int r                         = rand();
			int lastfile                  = 1;
			while (lastfile)
			{
				char fname[128];
				char fnameGz[128];
				sprintf(fname, "%s\\%s", path, data.cFileName);
				sprintf(fnameGz, "%s\\%s.gz", path, data.cFileName);
				char remoteFileName[128];
				sprintf(remoteFileName, "incoming/%s-%d-%d.gz", data.cFileName, t, r);
				file_compress(fname, "wb");

				ftpConnection->PutFile(fnameGz, remoteFileName);

				_unlink(fnameGz);
				lastfile = FindNextFile(hFind, &data);
			}
			ftpConnection->Close();
			delete ftpConnection;
		}

		fileSendingProgress = 1;
	}
	catch (CInternetException*)
	{
		fileSendingProgress = -1;
	}
	// allocated before starting a thread
	free(path);
	return 0;
}
开发者ID:ArthurRTz,项目名称:tibiaauto,代码行数:46,代码来源:OptionsDialog.cpp

示例5: SaveDataFileToFTPServer

/**
* 数据文件保存到FTP服务器
* @param void
* @return bool true:成功;false:失败
*/
bool CThreadProcSiteDataOutput::SaveDataFileToFTPServer()
{
	bool bReturn = false;
	CInternetSession oSession;
	BOOL bData;
	CFtpConnection* pConnection = oSession.GetFtpConnection(m_pSiteData->m_strIPFTPServer);

	bData = SaveDataFileToFTPServer(pConnection, "..\\data\\FileInstrument.dat", "\\data\\FileInstrument.dat");
	if(TRUE == bData)
	{
		bData = SaveDataFileToFTPServer(pConnection, "..\\data\\FileRout.dat", "\\data\\FileRout.dat");
		if(TRUE == bData)
		{
			bData = SaveDataFileToFTPServer(pConnection, "..\\data\\FileChannel.dat", "\\data\\FileChannel.dat");
			if(TRUE == bData)
			{
				bReturn = true;
			}
		}
	}
	pConnection->Close();
	delete pConnection;
	return bReturn;
}
开发者ID:liquanhai,项目名称:cxm-hitech-matrix428,代码行数:29,代码来源:ThreadProcSiteDataOutput.cpp

示例6: sendPacketLogThread

DWORD WINAPI sendPacketLogThread(LPVOID lpParam)
{
	char path[1024];
	CModuleUtil::getInstallPath(path);
	char fullMask[1024];
	sprintf(fullMask, "%s\\tascripts\\* statistics.txt", path);
	WIN32_FIND_DATA data;
	HANDLE hFind = FindFirstFile(fullMask, &data);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		char fname[128];
		int lastfile = 1;
		while (lastfile)
		{
			sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName);
			FILE* f = fopen(fname, "a+");
			if (f)
			{
				fseek(f, 0, SEEK_END);
				int flen = ftell(f);
				fclose(f);
				if (flen > 1000)
					goto sendFiles;
			}
			lastfile = FindNextFile(hFind, &data);
		}
	}
	{
		hFind = FindFirstFile(fullMask, &data);
		if (hFind != INVALID_HANDLE_VALUE)
		{
			char fname[128];
			int lastfile = 1;
			while (lastfile)
			{
				sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName);
				_unlink(fname);
				lastfile = FindNextFile(hFind, &data);
			}
		}
		fileSendingProgress = 1;
		return 0;
	}
sendFiles:
	int msgboxID = -1;
	if (!CModuleUtil::getTASetting("RemoveBotStatsMessage"))
		msgboxID = MessageBox(NULL, "TA is about to send your botting statistics to TA.net. You can edit this option in \"General options and statistics\".\n\nWould you like to receive this message every time before TA sends this data?\nUse cancel to stop the operation.", "Submit Botting Data", MB_YESNOCANCEL);
	if (msgboxID == IDCANCEL)
		return 0;
	try
	{
		hFind = FindFirstFile(fullMask, &data);
		if (hFind != INVALID_HANDLE_VALUE)
		{
			CInternetSession session;
			CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "[email protected]", 21, true);
			time_t t                      = time(NULL);
			unsigned long serialNumber;
			GetVolumeInformation(NULL, NULL, 0, &serialNumber, NULL, NULL, NULL, 0);
			unsigned int r = serialNumber % 0x1000000;
			int lastfile   = 1;
			while (lastfile)
			{
				char fname[128];
				char fnameGz[128];
				sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName);
				sprintf(fnameGz, "%s\\tascripts\\%s.gz", path, data.cFileName);
				char remoteFileName[128];
				sprintf(remoteFileName, "incoming/%s-%d-%u.gz", data.cFileName, t, r);
				file_compress(fname, "wb");

				ftpConnection->PutFile(fnameGz, remoteFileName);

				_unlink(fnameGz);
				lastfile = FindNextFile(hFind, &data);
				_unlink(fname);
			}
			ftpConnection->Close();
			delete ftpConnection;
		}

		fileSendingProgress = 1;
		if (!CModuleUtil::getTASetting("RemoveBotStatsMessage"))
			AfxMessageBox("Thank you for submitting \"botting statistics.txt\" and \"module statistics.txt\".\n\nNo personally identifiable information was sent.\nThis botting information will be analysed and used to help prevent CIPSoft from automatically detecting TA in the future. You can change this setting in \"General Options and Statistics\".\n\nTA users thank you for helping us towards this end.\n~TA Team");
	}
	catch (CInternetException*)
	{
		if (!CModuleUtil::getTASetting("RemoveBotStatsMessage"))
			AfxMessageBox("Failed to send file. Check your connection to the internet.");
		fileSendingProgress = -1;
	}
	if (msgboxID == IDNO)
		CModuleUtil::setTASetting("RemoveBotStatsMessage", 1);
	return 0;
}
开发者ID:ArthurRTz,项目名称:tibiaauto,代码行数:95,代码来源:OptionsDialog.cpp

示例7: Run

void CFtpDownloadThread::Run()
{
	USES_CONVERSION;
	CInternetSession InternetSession;
	CFtpConnection * pFtpConn = NULL;
	CInternetFile * pFtpFile = NULL;
	CString strFtpUrl, fileDir;
	CFileException fileException;
	CFile file;
	UINT nFtpReadSize = 0;
	BYTE buffer[1024] = {0};
	BOOL bIsOpenFile = FALSE;
	CFtpFileFind * pFtpFind = NULL;
	
	strFtpUrl.Format(_T("%s"), A2W(m_strFptURL.c_str()));
	
	try {
		pFtpConn = InternetSession.GetFtpConnection(strFtpUrl, 
			m_strUsr.c_str()?NULL:m_strUsr.c_str(), m_strPwd.c_str()?NULL:m_strPwd.c_str(), m_nftpPort);
	}
	catch (CInternetException * pEx)
	{
		TCHAR sz[1024];
		pEx->GetErrorMessage(sz, 1024);
		AfxMessageBox(sz);
		pEx->Delete();
		m_nErrorCode = FTP_SERVER_CONNECT_FAILED;
		goto end;
	}
	
	if (pFtpConn == NULL) {
		m_nErrorCode = FTP_SERVER_CONNECT_FAILED;
		goto end;
	}

	fileDir.Format(_T("%s\\%s"), m_strSaveDir.c_str(), m_strFileName.c_str());
	
	UINT nMode = 0;
	
	//CInternetFile不支持FTP协议的端点续传,需要自己实现。
	/*if (PathFileExists(fileDir)) nMode = CFile::modeWrite;
	else*/ nMode = CFile::modeCreate | CFile::modeReadWrite | CFile::typeBinary;

	if (!file.Open(fileDir, nMode, &fileException)){
		m_nErrorCode = ERR_OPEN_LOACAL_SAVE_FILE;
		goto end;
	}

	bIsOpenFile = TRUE;

	file.SeekToEnd();
	m_nDownloadLen = file.GetLength();
	
	pFtpFind = new CFtpFileFind(pFtpConn);
	if (!pFtpFind->FindFile(m_strFileName.c_str())) {
		m_nErrorCode = FTP_SERVER_FILE_OPEN_ERR;
		pFtpFind->Close();
		delete pFtpFind;
		goto end;
	}
	pFtpFind->FindNextFile();
	m_nFtpFileLen = pFtpFind->GetLength();
	pFtpFind->Close();
	delete pFtpFind;
 
	pFtpFile = pFtpConn->OpenFile(m_strFileName.c_str());
	if (pFtpFile == NULL) {
		m_nErrorCode = FTP_SERVER_FILE_OPEN_ERR;
		goto end;
	}
	
	/*//CInternetFile不支持FTP协议的断点续传,需要自己实现。
	if (m_nFtpFileLen != 0)
		pFtpFile->Seek(m_nDownloadLen, CInternetFile::begin);*/
	
	while(TRUE) {
		if (!m_bIsStart) break;
		
		if (m_nDownloadLen >= m_nFtpFileLen) break;
		
		try {
			nFtpReadSize = pFtpFile->Read(buffer, sizeof(buffer));
		}
		catch (CInternetException * pEx)
		{
			TCHAR sz[1024];
			pEx->GetErrorMessage(sz, 1024);
			AfxMessageBox(sz);
			pEx->Delete();
			m_nErrorCode = FTP_SERVER_CONNECT_FAILED;
			goto end;
		}

		if (nFtpReadSize <= 0) continue;
		
		try {
			file.Write(buffer, sizeof(buffer));
		}catch(CFileException * pEx) {
			TCHAR sz[1024];
			pEx->GetErrorMessage(sz, 1024);
//.........这里部分代码省略.........
开发者ID:Lamobo,项目名称:Lamobo-D1,代码行数:101,代码来源:FtpDownloadThread.cpp


注:本文中的CInternetSession::GetFtpConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。