如题.大家能否给个例子?

解决方案 »

  1.   

    int NetPutByFile(char *szLocalName)
    {
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];
    char fname[_MAX_FNAME];
    char ext[_MAX_EXT];
    char szDirName[MAX_PATH];
    DWORD dwLen=MAX_PATH;
    CFtpConnection *pFtpConn=NULL;
    if(szLocalName==NULL) return NETFTP_NOFILE; _splitpath(szLocalName,drive,dir,fname,ext );
    strcat(fname,ext);

    try
    {
    g_pInetSession=new CInternetSession;
    pFtpConn=g_pInetSession->GetFtpConnection(g_szIP,g_szUserName,g_szPassWord);


    pFtpConn->GetCurrentDirectory(szDirName,&dwLen);
    xprintf("Current Directory:%s\n",szDirName);
    pFtpConn->CreateDirectory(g_szServerDir);
    pFtpConn->SetCurrentDirectory(g_szServerDir);
    char seps[]="\\";
    char *token;
    token=strtok(dir,seps);
    while(token!=NULL)
    {
    pFtpConn->CreateDirectory(token);
    pFtpConn->SetCurrentDirectory(token);
    token=strtok(NULL,seps);
    } DWORD dwFlags=FTP_TRANSFER_TYPE_BINARY;
    if(IsAscii(ext)) dwFlags=FTP_TRANSFER_TYPE_ASCII;
    if(!pFtpConn->PutFile(szLocalName,fname,dwFlags))
    {
    printf("文件传送失败!\n");
    if(pFtpConn) delete pFtpConn;
    if(g_pInetSession) delete g_pInetSession;
    return GetLastError();
    }
    GetExtendMessage();
    pFtpConn->Close();
    g_pInetSession->Close();
    } catch(CInternetException *e)
    {
    e->Delete();
    printf("无法连接到主机!\n");
    }
    if(g_pInetSession) delete g_pInetSession;
    if(pFtpConn) delete pFtpConn;

    return NETFTP_OK;
    }