FTP传数据的问题? 
我有一个数据文件(M 行 * N 行的二进制文件raw的图像 )要用FTP功能发送出去,
但要求读一行数据发一行数据,直到文件结束,而不是用FTP一次将文件发出去;
因原是数据文件是由另程序按时间一行一行生成的,为了时效性,要求当文件
生成后,同时也被发送完成了。
不知如何去作呢?多谢!

解决方案 »

  1.   

    没做过!不过有个呆一点的思路:每读一行数据写到临时文件;每次上传到服务器上,把临时文件写到文件的末尾!
    CInternetFile::Write
    virtual void Write( const void* lpBuf, UINT nCount );
    throw CInternetException( );ParameterslpvBufA pointer to the first byte to be written.nCountSpecifies the number of bytes to be written.ResCall this member function to write into the given memory, lpvBuf, the specified number of bytes, nCount. If any error occurs while writing the data, the function throws a CInternetException describing the error.
      

  2.   

    ////发送线程
    连接服务器
    打开文件上传的连接
    while(1)
    {
    阻塞等信号;
    读取1行;
    发送一行;
    }
    //////
    另1线程写完1行后发信号
    ///
    不知道行不行呢,我对FTP协议不是很了解。
      

  3.   

    使用RSET指令就可以了,如果对方支持断点续传的话
    请参考RFC文档
    这样如果每隔5分钟传一次,
    只要取得文件长度,
    使用RESET指令将指针移动到最后,使用添加数据就可以了。
      

  4.   

    生成文件的程序用共享模式打开文件,然后写。
    发送程序也用共享模式打开文件读,边读边发送,读到文件尾后,Sleep 一段时间再读,如果有数据再发送,只要调节好sleep 时间就可以了。
    举个简单例子。生成文件的程序
    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    #define NAME "c:\\test.dat"
    int main(int argc, char* argv[])
    {
    HANDLE hFile = CreateFile(NAME,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    if(hFile == INVALID_HANDLE_VALUE)  return -1;
    for(int i=0;i< 10;i++) {
    DWORD len = 0;
    printf("Writing %d to file\n",i);
    WriteFile(hFile,&i,sizeof(i),&len,NULL);
    Sleep(3000); //模仿生成文件时的延时
    }
    CloseHandle(hFile);
    return 0;
    }
    发送程序:
    #include "stdafx.h"
    #include <stdio.h>
    #include <windows.h>
    #define NAME "c:\\test.dat"
    int main(int argc, char* argv[])
    {
    HANDLE hFile = CreateFile(NAME,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    if(hFile == INVALID_HANDLE_VALUE)  return -1;
    int data;
    DWORD len = 0;
    int nTry = 0;
    while(ReadFile(hFile,&data,sizeof(data),&len,NULL))
    {
    if( len == 0 ) {
    if(nTry>3) break;
    Sleep(2000); //等待2秒再读,共试三次
    nTry++;
    continue;
    }
    nTry = 0;
    //You can send data to FTP server here
    printf("Read %d\n",data);
    } CloseHandle(hFile);
    return 0;
    }
      

  5.   

    Ftp服务方是Windows2000的IIS的FTP服务啊!
      

  6.   

    现在我以共享方式读文件,显示数据都已作好了,就是不知道如何将数据
    一行一行的通过FTP发送到W2000的IIS的FTP服务器上啊?
      

  7.   

    我是VC新手啦!
    连接FTP是不是选
    #include "afxinet.h"
    #include "afxtempl.h"
    CInternetSession* m_pInetSession; //会话对象
    CFtpConnection* m_pFtpConnection; //连接对象
    //新建对话
    m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
    try 

    //新建连接对象
    m_pFtpConnection=m_pInetSession->GetFtpConnection(m_strServer,m_strUserName,
    m_strPassword); 

    catch(CInternetException *pEx) 
    {
    }
    发送时如何发啊!…
    总不能m_pFtpConnection->PutFile( strLocalFile,strRemoteFile));
    按文件发吧?
      

  8.   

    CFtpConnection::OpenFile  // open a remote file to write
    CInternetFile::Write  // write the data to the remote file
    CInternetFile::Close