SOCKET dd;
        char p_buf[1024];
cout<<"Please input your filename:";
cin>>p_buf;
int slen=strlen(p_buf);
p_buf[slen]=0;//p_buf用来存储文件路径
Sendmsg(s,"STOR ",p_buf);//Sendmsg是我自定义的函数,没问题。
iLen=recv(s,r_buf,1024,0);
r_buf[iLen]=0;
cout<<r_buf<<endl;
 
        FILE *rw;
long lenseek;
rw=fopen(p_buf,"rb");
fseek(rw,0,SEEK_END);
lenseek=ftell(rw);
cout<<"文件大小:"<<lenseek<<endl;
fread(p_buf,lenseek,1024,rw);//问题代码,不知是否如此写入
fclose(rw);
send(dd,p_buf,strlen(p_buf),0);目前的问题是,上传文件后文件内容会变成文件名,请问如何解决?

解决方案 »

  1.   

    char *p_buf = "C:\\aa.txt";
    char *ppbuf = NULL;
    FILE *rw;
    long lenseek;
    rw=fopen(p_buf,"rb");
    fseek(rw,0,SEEK_END);//怀疑这三句有问题
    lenseek=ftell(rw);//怀疑这三句有问题
             ppbuf = new char[lenseek + 1];
             memset(ppbuf ,0 , lenseek + 1);
    fseek(rw,0,SEEK_SET);//重置
    fread(ppbuf ,lenseek,1,rw);//读取内容
    fclose(rw);
    cout<<ppbuf <<endl;1、文件要重新定位到头部;
    2、不要用文件名的那个字符串再接收文件内容(接收文件内容的缓冲要足够大);
      

  2.   

    fseek(rw,0,SEEK_END);
    lenseek=ftell(rw);
    cout<<"文件大小:"<<lenseek<<endl;
    fread(p_buf,lenseek,1024,rw);//问题代码,不知是否如此写入
    fclose(rw);指针没移回去,fread只前加个fseek(sw,0,SEEK_SET);