DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Output stream failed

  1. #1
    Join Date
    Nov 2006

    Output stream failed

    Hi All,
    I have a 2GB file.Iam trying to collect that file using FTP.
    Below is the code

    const unsigned long FTPClient::getFile(TCPSocket* theTransferSocket,
    ostream& theLocalStream) const
    unsigned long tbr = 0; // Total bytes received.
    tbr = getBinaryFile(theTransferSocket, theLocalStream);
    if (!theLocalStream) { cerr<<"output stream failed "<<endl;
    throw FTPException("Error on output stream."); }
    cerr<<" number of bytes read in getFile() tbr="<<tbr<<endl;
    return tbr;


    const unsigned long FTPClient::getBinaryFile(TCPSocket* theTransferSocket,
    ostream& theLocalStream) const
    throw (FTPException&)
    cerr<<"==getBinaryFile() =="<<endl;
    static const int TMP_BUFSIZ = 2048;
    char tmpBuffer[TMP_BUFSIZ];
    unsigned long tbr = 0; // Total bytes read.
    unsigned long nobr = 0; // No. of bytes read.

    while((nobr =
    theTransferSocket->read( tmpBuffer, TMP_BUFSIZ, myTimeOut )) > 0)
    theLocalStream.write(tmpBuffer, nobr);
    tbr += nobr;
    cerr<<"==changed to unsigned long int=="<<endl;
    cerr<<"== Total bytes read = "<<tbr<<endl;
    catch (SocketException& theExc) {
    theExc.addReason("Failed to receive binary buffer.");
    throw FTPException(theExc);
    if( nobr == -1 )
    throw FTPException( "Failed to receive BINARY file. Socket timed out.", AlarmType::FTP_TIMEOUT );
    cerr<<"==b4 end of getBinaryFile() =="<<endl;
    cerr<<"== Total bytes read = "<<tbr<<endl;
    return tbr;

    when execute the above snippet...
    it is saying
    == Total bytes read = 2998908000
    output stream failed

    the file size is same as above
    but iam not able to find why that ostream is getting failed ....
    after reading all bytes.

    Could you find any hints and let me know if you have any


  2. #2
    Join Date
    May 2006
    In my opinion if theTransferSocket->read returns a negative value in case of error, then you do not detect it because of used unsigned variables.

    I would suggest you to check the return type of read function, adjust variables and try again. It should be a method for obtaining error’s details (like reading the errno variable).

    I hope this helps.

  3. #3
    Join Date
    Oct 2005
    I think the problem is with the TMP_BUFSIZ , it's too large for sockets to get this stream .. I'm not sure .

  4. #4
    Join Date
    Nov 2003
    I agree with Viorel. Using an unsigned value is dangerous because the erro code are usually negative. Use signed long. I know it's a borderline case, since if the file exceeds the 2GB size, this size can't be represented. However, a file larger than 2GB is illegal on many systems anyway, so it should be OK. In any event, you have to check the return code from each read() call before you proceed. Also notice that throwing an exception without adding some information about the nature of the problem doesn't help much, so the exception object itself should somehow store the error code.
    Danny Kalev

  5. #5
    Join Date
    Nov 2006
    Thanx for replies
    But I tried with signed longa also.
    In that case also it is getting failed.
    Of course solaris supports files upto 4GB size.
    The socket is able to read data correctly,but when it is writing that data into stream
    it is failed exactly after 2GB of data.
    Later I found the below....

    cout<<std::numeric_limits<std::streamsize>::max();<< ----giving 2147483647

    I came to know that streams will support upto 2GB of data only.
    Is there any other way to work around the problem of handling large files?
    Is there any special libraries for these things?

    Thank U

  6. #6
    Join Date
    Oct 2005
    Since it can reads all the file size , u can split the transfere .. and to be sure af the correction split after every 1GB say .

Similar Threads

  1. Replies: 5
    Last Post: 11-13-2009, 02:28 AM
  2. Replies: 1
    Last Post: 04-24-2008, 06:03 AM
  3. Replies: 0
    Last Post: 11-28-2005, 01:56 PM
  4. Memory Stream
    By Hunterlmc in forum .NET
    Replies: 1
    Last Post: 07-25-2005, 05:39 AM
  5. Socket I-O Stream Multi-Threading
    By bowena in forum Java
    Replies: 2
    Last Post: 09-28-2002, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center