Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > VC++ _popen to call ftp and pipe output to a file, cannot open file?

Reply
Thread Tools

VC++ _popen to call ftp and pipe output to a file, cannot open file?

 
 
Michael
Guest
Posts: n/a
 
      12-01-2004
Hello,

Not sure if this is the right message board but I have an interesting
problem.

Using Visual Studio .NET, C++, I want to write an all-encompassing C++
program to download new files from an FTP Server. The C++ program will
ftp to the server and download a list of files, match those files with
the ones I've already received, put together a new ftp script and
download.

I am using _popen to call FTP.

My problem is this, _popen calls ftp and pipes the output to a .txt
file, then the C++ program tried to open the .txt file and fails. It's
as if the C++ program is not waiting for the _popen to complete and
_popen still has the file open so my next statement to attempt opening
fails. Is there a way around this?

Here is a bit of my code:

// Call _popen and capture output for errors
FILE *pPipe;
char my_command[200];
sprintf(my_command,"ftp -v -i -s:%s >
%s",ftp_filename,output_filename);
if ((pPipe = _popen(my_command,"rt"))==NULL)
{
cout << "FTP FAILURE" << endl;
exit(1);
}
fclose(pPipe);

// Open Output File
sfile.open(output_filename,ios::in);
if(!sfile)
{
cout << "Could not open: " << output_filename << endl;
return -1;
}

The "if(!sfile)" is always TRUE, so the program fails.

Thanks in advance for the assistance!
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      12-01-2004
Michael wrote:

> // Open Output File
> sfile.open(output_filename,ios::in);


Does output_filename actually exist?
What is sfile? Hopefully it's an ifstream or such.

> if(!sfile)
> {
> cout << "Could not open: " << output_filename << endl;


You might want to try GetLastError or some other Windows call that might
give you a better explanation of the failure.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fseek on a file opened with _popen thomas.mertes@gmx.at C Programming 15 02-29-2008 08:36 AM
Regarding _popen() in windows 2000 painulyarun@gmail.com Ruby 2 09-21-2007 06:05 AM
system() or _popen()? Michael C++ 2 11-12-2004 11:55 AM
[named pipe] i wanna know about validate of pipe handle of client lee, wonsun C++ 1 11-02-2004 04:29 AM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM



Advertisments