Solved

ftp upload in vc++

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

23 Experts available now in Live!

Get 1:1 Help Now