Solved

ftp upload in vc++

Posted on 2004-04-08
4
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

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

Expert Comment

by:rockiroads
ID: 10787892
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
ID: 10787895
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
ID: 10794948
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.

752 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