Solved

ftp upload in vc++

Posted on 2004-04-08
4
413 Views
Last Modified: 2012-06-27
hi experts,

i want to upload a file to ftp using following code:

m_intsession = new CInternetSession();
m_connection=m_intsession -> GetFtpConnection(FTPServerVal,FTPUserVal,FTPPassVal);
CString str, source, target ;
CInternetFile *pfile ;
CFile fp ;
UINT count ;
source = "accessread.txt";
target = "accessread.txt";
fp.Open ( source, CFile::modeRead) ;
pfile = m_connection -> OpenFile ( target, GENERIC_WRITE, FTP_TRANSFER_TYPE_BINARY, 0 ) ;
pfile -> WriteString(ResultVar);
pfile -> Close( ) ;
fp.Close( ) ;

everything works fine... the file also gets uploaded (provided i press the ignore button in the following error message-box)...
the only problem is, i get the following error when "pfile -> WriteString(ResultVar);" is called:

Debug Assertion Failed

File: inet.cpp
Line: 1137

since i am a newbie in vc++ i dont know what to do...
please help me...
0
Comment
Question by:obiwankenobi6bone
  • 2
4 Comments
 

Author Comment

by:obiwankenobi6bone
Comment Utility
ahhh... forgot to say that the variable ResultVar is a CString...
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
just a thought, maybe you should check the return values of your called functions

pfile is set by m_connection

perhaps pfile is not set correctly hence the error
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
always good practice to check return variables for failures

look in help for all the system calls you make for errors (been ages since I did C++)
0
 
LVL 1

Accepted Solution

by:
hal3000 earned 500 total points
Comment Utility
I have difficulty understanding how your file gets uploaded.

How is ResultVar initialized? Using the WriteString method it should contain the entire contents of the file to be transferred. Therefore you would have to read the local file into ResultVar. If the local file is a binary file and contains embedded null characters WriteString will only transfer data up to the first null character.

To get around that you would have to create a buffer large enough to contain the entire file, read the file into it, and then use the Write method.


Of course there is a simpler way use the PutFile method which does it all for you.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
This is an explanation of a simple data model to help parse a JSON feed
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now