FTP传数据的问题?

shally5 2004-04-17 10:59:33
FTP传数据的问题?
我有一个数据文件(M 行 * N 行的二进制文件raw的图像 )要用FTP功能发送出去,
但要求读一行数据发一行数据,直到文件结束,而不是用FTP一次将文件发出去;
因原是数据文件是由另程序按时间一行一行生成的,为了时效性,要求当文件
生成后,同时也被发送完成了。
不知如何去作呢?多谢!
...全文
61 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
w3guy 2004-04-19
  • 打赏
  • 举报
回复
CFtpConnection::OpenFile // open a remote file to write
CInternetFile::Write // write the data to the remote file
CInternetFile::Close
shally5 2004-04-19
  • 打赏
  • 举报
回复
我是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));
按文件发吧?
sboom 2004-04-18
  • 打赏
  • 举报
回复
上面不是说了么。
itmaster 2004-04-18
  • 打赏
  • 举报
回复
学习
w3guy 2004-04-18
  • 打赏
  • 举报
回复
生成文件的程序用共享模式打开文件,然后写。
发送程序也用共享模式打开文件读,边读边发送,读到文件尾后,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;
}

shally5 2004-04-18
  • 打赏
  • 举报
回复
现在我以共享方式读文件,显示数据都已作好了,就是不知道如何将数据
一行一行的通过FTP发送到W2000的IIS的FTP服务器上啊?
shally5 2004-04-18
  • 打赏
  • 举报
回复
Ftp服务方是Windows2000的IIS的FTP服务啊!
danscort2000 2004-04-18
  • 打赏
  • 举报
回复
使用RSET指令就可以了,如果对方支持断点续传的话
请参考RFC文档
这样如果每隔5分钟传一次,
只要取得文件长度,
使用RESET指令将指针移动到最后,使用添加数据就可以了。
sboom 2004-04-18
  • 打赏
  • 举报
回复
////发送线程
连接服务器
打开文件上传的连接
while(1)
{
阻塞等信号;
读取1行;
发送一行;
}
//////
另1线程写完1行后发信号
///
不知道行不行呢,我对FTP协议不是很了解。。。。
jinxuliang 2004-04-17
  • 打赏
  • 举报
回复
没做过!不过有个呆一点的思路:每读一行数据写到临时文件;每次上传到服务器上,把临时文件写到文件的末尾!
CInternetFile::Write
virtual void Write( const void* lpBuf, UINT nCount );
throw CInternetException( );

Parameters

lpvBuf

A pointer to the first byte to be written.

nCount

Specifies the number of bytes to be written.

Remarks

Call 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.

暗黑帝国 2004-04-17
  • 打赏
  • 举报
回复
gz

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧