我现在用CInternetSession,CHttpConnection,CHttpFile这几个类来实现上传文件到服务器
但是我总是不成功
不知道谁能给出相类似的代码我参考参考?
还有就是IIS服务器这边应该如何设置才能上传文件

解决方案 »

  1.   

    我看在服务器IIS上设置那个默认的FTP站点就可以了
      

  2.   

    the same as me.
    up up up ...
      

  3.   

    连设置IIS都不会吗?
    控制面板-》管理工具-》Internet服务管理器-》默认FTP站点
    然后就是具体设置了,这个你看书吧,这里说不清楚。
    //上传单个文件到FTP服务器默认目录
    #include "afxinet.h"try{
    CInternetSession* m_pInetSession = new CInternetSession(_T("FtpDownload"),1,PRE_CONFIG_INTERNET_ACCESS);; //会话对象
    CFtpConnection* m_pFtpConnection= m_pInetSession->GetFtpConnection("服务器IP","FTP帐号","密码",21); //连接对象
    if( m_pFtpConnection->PutFile("要上传的文件","新文件名") == FALSE )
    {
    LPVOID lpMsgBuf;
    FormatMessage( 
    FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    (LPTSTR) &lpMsgBuf,
    0,
    NULL 
    ); CString sWarning;
    sWarning.Format( "文件上传错误:%s", lpMsgBuf );
    ::MessageBox( NULL, sWarning, "ftp传输错误", MB_OK );
    LocalFree( lpMsgBuf );
    m_pInetSession->Close();
    delete m_pInetSession;
    return FALSE;
    }
    else
    {
    ::MessageBox( NULL, "文件上传成功!", "提示", MB_OK );
    m_pInetSession->Close();
    delete m_pInetSession;
    }
    }catch( CInternetException  *e )
    {
    char szError[ 1024];
    e->GetErrorMessage( szError, 1024 );
    ::MessageBox( NULL, szError, "ftp连接错误", MB_OK );
    return FALSE;
    }
      

  4.   

    frontpage extension service
    or
    webDAV