Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

ftp upload in vc++

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
obiwankenobi6bone
Asked:
obiwankenobi6bone
  • 2
1 Solution
 
obiwankenobi6boneAuthor Commented:
ahhh... forgot to say that the variable ResultVar is a CString...
0
 
rockiroadsCommented:
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
 
rockiroadsCommented:
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
 
hal3000Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now