Solved

ftp upload in vc++

Posted on 2004-04-08
4
416 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change the background and font colors in Notepad++ 5 118
"Black Box" Testing of Control System Software 2 72
Why use this lambda? 12 41
batch file or script 4 28
This is about my first experience with programming Arduino.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

821 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