Exemple #1
0
BOOL CFtpFileDlg::GetFile( 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->GetFile(strSourceName,strDesName)){
			pConnection->Close();
			delete pConnection;
			delete pSession;
			return FALSE;
		}
	}
	if (pConnection != NULL){
		pConnection->Close();
		delete pConnection;
	}
	delete pSession;
	return TRUE;
}
Exemple #2
0
vmd_ftpclient(const char * site, 
            const char * remotefile, 
            const char * localfile) {
  CInternetSession S("Eagle FTP"); 
  CFtpConnection *f; 

  try { 
    f = S.GetFtpConnection(site,
                           "anonymous",
                           "*****@*****.**",
                           21,
                           FALSE); 
    f->SetCurrentDirectory("/"); 
    f->GetFile(remotefile, localfile,
               FALSE,
               FILE_ATTRIBUTE_NORMAL,
               FTP_TRANSFER_TYPE_BINARY,
               1);
    
    delete f; 
    S.Close(); 
  
    return FTP_SUCCESS;
  } 

  catch (CInternetException) { 
    printf("FTP Error!\n"); 
    return FTP_FAILURE;
  } 

  return FTP_SUCCESS;
} 
Exemple #3
0
bool CFTPDlg::GetFtpFile()
{
	CInternetSession sess(0, 0, INTERNET_OPEN_TYPE_DIRECT);
	unsigned long timeOut = 300000;
	sess.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, timeOut);
	sess.SetOption(INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT, timeOut);    
	sess.SetOption(INTERNET_OPTION_CONTROL_SEND_TIMEOUT, timeOut);    
	sess.SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, timeOut * 10);    
	sess.SetOption(INTERNET_OPTION_DATA_SEND_TIMEOUT, timeOut * 10);    
	sess.SetOption(INTERNET_OPTION_SEND_TIMEOUT, timeOut);  
	sess.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, timeOut * 10);  
	sess.SetOption(INTERNET_OPTION_DISCONNECTED_TIMEOUT, timeOut);  
	sess.SetOption(INTERNET_OPTION_FROM_CACHE_TIMEOUT, timeOut);  
	sess.SetOption(INTERNET_OPTION_LISTEN_TIMEOUT, timeOut);  

	CString strMsg;
	bool isFileExist = false;
	m_progress.SetPos(0);
	try
	{      
		CString sHost;
		CString sUsername; 
		CString sPassword; 
		CString sPort; 
		m_host.GetWindowText(sHost);
		m_name.GetWindowText(sUsername);
		m_pwd.GetWindowText(sPassword);
		m_port.GetWindowText(sPort);
		int nPort  = atoi(sPort); 
#ifdef FTP_PASSIVE
		CFtpConnection* pConnect = sess.GetFtpConnection(sHost, sUsername, sPassword, nPort, false);
#else
		CFtpConnection* pConnect = sess.GetFtpConnection(sHost, sUsername, sPassword, nPort, true);
#endif
		strMsg.Format("connect to %s successful!", sHost);
		m_text.SetWindowText(strMsg);

		CString strLocalName, strRemotePath;
		strLocalName = m_ephFileName;
		strRemotePath.Format("ephemeris\\%s", strLocalName);

		strMsg.Format("Downloading %s from %s", strLocalName, sHost);
		m_text.SetWindowText(strMsg);
		if(!pConnect->GetFile(strRemotePath, strLocalName, false))
		{
			DWORD err = GetLastError();
			strMsg = Utility::ErrorString(err);
			AfxMessageBox(strMsg);
		}
		else
		{
			isFileExist = true;
		}

		if(pConnect != NULL)
		{
			pConnect->Close();
		}
		delete pConnect;
	}
	catch (CInternetException* pEx)
	{
		TCHAR sz[1024];
		pEx->GetErrorMessage(sz, 1024);
		printf("ERROR!  %s\n", sz);
		pEx->Delete();
		AfxMessageBox(sz);
	}

	return isFileExist;
}