现在在做一个系统集成的项目,时间较紧,对FTP下载和上传不是很熟,现在的问题是我该如何定时自动上传指定文件夹里面的文件到指定的FTP服务器,文件会不停的变化,文件名也不相同,希望大家能帮帮忙,最好能够提供源代码,谢谢了!!

解决方案 »

  1.   

    CString      csError;
    HINTERNET    hIntSession = 0; 
    HINTERNET    hFtpSession = 0; BOOL         bSuccess = FALSE; hIntSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL);
    if ( NULL == hIntSession )
    {
    csError = _T("无法访问网络!");
    goto ERROR_EXIT;
    } hFtpSession = InternetConnect( hIntSession, m_csFtpip, m_lFtport, m_csFtpusr, m_csFtpswd, INTERNET_SERVICE_FTP, 0, 0);
    if ( NULL == hFtpSession )
    {
    csError = _T("无法连接 FTP 服务器!");
    goto ERROR_EXIT;
    } if ( m_csFtprdir.IsEmpty() )  // 远程目录为空,设为根目录
    {
    m_csFtprdir = "/";
    bSuccess = FtpSetCurrentDirectory( hFtpSession, m_csFtprdir);
    if ( !bSuccess )
    {
    csError = _T("无法设置当前目录");
    goto ERROR_EXIT;
    }
    }
    else
    {
    // 分析目录,不存在则创建,暂缺,待补 2007-01-07
    bSuccess = FtpSetCurrentDirectory( hFtpSession, m_csFtprdir);
    if ( !bSuccess )
    {
    csError = _T("远程目录不存在!");
    goto ERROR_EXIT;
    }
    }         ///////////////////////////////
             可在这里实现上传,用FtpPutFile
             对于你的指定文件夹可进行遍历,调用FtpPutFile 上传每一个
             /////////////////////////////// InternetCloseHandle(hFtpSession);
    InternetCloseHandle(hIntSession); MessageBox( _T("连接成功,上传配置正确"), _T("提示"), MB_OK | MB_ICONINFORMATION );
    return ;ERROR_EXIT:
    if ( hFtpSession )
    {
    InternetCloseHandle(hFtpSession);
    } if ( hIntSession )
    {
    InternetCloseHandle(hIntSession);
    }

    MessageBox( csError, _T("提示"), MB_OK | MB_ICONINFORMATION );
    return ;至于定时处理结合你的项目应该很好实现,不多说了