设想一:是否可以像是对本地生成的文本文档的操作,对其写入自己的IP地址  设想二:在本地上生成一个 IP.TXT 文件,把自己的IP写进去,然后上传到FTP空间
不知道这两种方法那种可行?或是实现起来比较简单还有什么好的方法?  在实现的时候都需要些什么?最好是能给个例程   谢谢   org

解决方案 »

  1.   

    我已经在尝试设想二的方法,实现了
    在本地上生成一个 IP.TXT 文件,把自己的IP写进去现在遇到新问题: 不知道如何传到FTP上去  具体应该如何实现 用到什么相关函数? 是否有例程 提供 谢谢
      

  2.   

    FTP要自己实现,看一下FTP协议,不难的。
      

  3.   

    设想一应该也可以
    虽然具体的我没做过
    不过你可以去搜一下
    CFtpConnection
      

  4.   

    给你一段代码很简单的    m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
    try
    {
    //新建连接对象
    m_pFtpConnection=m_pInetSession->GetFtpConnection(sFtpUrl,sFtpUser,sFtpPassword);
    }
    catch(CInternetException *pEx)
    {
    //获取错误
    TCHAR szError[1024];
    if(pEx->GetErrorMessage(szError,1024))
    {m_log.AppendString(szError);
    exit(1);
    }
    else
    {
    m_log.AppendString("There Was an exception");
    pEx->Delete();
    m_pFtpConnection=NULL;
    exit(1);
    }
    } m_log.AppendString("连接ftp网址成功");
        m_pRemoteFinder = new CFtpFileFind(m_pFtpConnection);之后用m_pFtpConnection->PutFile(本地文件,上传文件)完了
      

  5.   

    恩我查了一下,应该是可以的
    PutFile is a high-level routine that handles all of the operations associated with storing a file on an FTP server. Applications that only send data, or that require closer control over the file transfer, should use OpenFile and CInternetFile::Write.
    Override the dwContext default to set the context identifier to a value of your choosing. The context identifier is associated with this specific operation of the CFtpConnection object created by its CInternetSession object. The value is returned to CInternetSession::OnStatusCallback to provide status on the operation with which it is identified. See the articleInternet First Steps: WinInet for more information about the context identifier.分享一下  
      

  6.   

    我申请了一个FTP空间  连接也没有问题,  其实我在尝试做FTP的客户端,想添加如题的功能,很感谢你的建议
      

  7.   

    生命如下:
    CInternetSession * m_pInetSession; //会话对象
    CFtpConnection * m_pFtpConnection; //连接对象
    CFtpFileFind * m_pRemoteFinder; //远程查找文件对象
    CFileFind m_LocalFinder; //本地查找文件对象
    希望对你有帮助
      

  8.   

    m_pInetSession=new CInternetSession
    说明 m_pInetSession 就是 CInternetSession类型的指针看返回值,定义
      

  9.   

    #include <afxinet.h>
    CInternetSession类
      

  10.   

    其实我是想问 pEx 和 m_log  还有 appstring函数声明 我猜测是在主程序中显示用的 所以做了如下修改:
    CInternetSession* m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
    CFtpConnection* m_pFtpConnection;
    try
    {
    //新建连接对象
     m_pFtpConnection=m_pInetSession->GetFtpConnection(sFtpUrl,sFtpUser,sFtpPassword);
    }
    catch(CInternetException *pEx)
    {
    //获取错误
    TCHAR szError[1024];
    if(pEx->GetErrorMessage(szError,1024))
    {//m_log.AppendString(szError);
    MessageBox(szError);
    exit(1);
    }
    else
    {
    MessageBox("There Was an exception");
    pEx->Delete();
    m_pFtpConnection=NULL;
    exit(1);
    }
    }

    MessageBox("连接ftp网址成功");

    CFtpFileFind* m_pRemoteFinder = new CFtpFileFind(m_pFtpConnection);
    if(!m_pFtpConnection->PutFile("D://ip.txt","D://ip.txt"))
    {
    MessageBox("未发送成功");
    }
    经过调试发现:FTP连接是没有问题的 因为我先后使用了错误的域名 密码 用户名 爆出不同的错误提示  均正确 则 连接成功  
    但是接下来会提示 未发送成功  说明m_pFtpConnection->PutFile("D://ip.txt","D://ip.txt")为空,也就是没有发送   求解惑 我该如何解决 谢谢
      

  11.   

    回复:
    1,pEx生命
    catch(CInternetException *pEx) 代码中已有2,m_log 还有 appstring函数声明
    这个是我的写日志类,你直接注销掉就行了3,if(!m_pFtpConnection->PutFile("D://ip.txt","D://ip.txt"))
    你这行有问题,看一下msdn就会明白,怎么能把D://ip.txt 上传到D://ip.txt这个呀,肯定是错误的
      

  12.   

    路径错误是因为 没有错误提示 我猜想是 FTP服务器的路径规则不熟悉 尝试了  D://ip.txt ://ip.txt  ip.txt等,但是都没有上传成功 我在回帖的时候忘记把那段改过来了   我今天晚上 在尝试过程中无意中 看到这篇帖子 http://topic.csdn.net/t/20041212/09/3637368.html
    对函数GetFtpConnection(sFtpUrl,sFtpUser,sFtpPassword,21,true); 参数做了修改 后成功上传了  在此分享下  非常感谢大家的帮助 特别是lvxinjian_cn