Solved

FTP

Posted on 2004-08-24
4
223 Views
Last Modified: 2010-04-01
I have a C++ application that uses ftp to pull data to the local machine for processing and displaying.  I execute the ftp process by using spawnlp to start ftp and run a file containing all of the ftp commands.  Everything works fine except for a little display issue.  Whenever ftp is fun, all of the ftp commands are displayed in the command window that the application is currently running in.  It displays all of the commands that exist in the file passed to ftp.  Is there any way to run ftp without having the commands displayed?????????

Thanks,
kendal
0
Comment
Question by:gvector1
  • 2
  • 2
4 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11884482
>>Is there any way to run ftp without having the commands displayed?

You can run it even completely hidden, using

DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd, BOOL bHide)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                           msg;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   bHide ? SW_HIDE : SW_SHOWNORMAL;

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                   &pi.hProcess,
                                                                   FALSE,
                                                                   INFINITE,
                                                                   QS_ALLINPUT
                                                               )
           )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);
}

and call it like

ExecuteAndWaitForCompletion ( "ftp.exe <cmdfile>", TRUE);

Or, if you don't have to wait for the program to finish,

WinExec ( "ftp.exe <cmdfile>", SW_HIDE);

will do also.
0
 

Author Comment

by:gvector1
ID: 11946549
I just recently was able to try the recommendations and they work wonderful, but the ftp commands from the <cmdfile> are still echoing in the calling dos window.  The dos window is used to run the application before and after the call.  It is just that when ftp is called, the commands are echoed on the screen.  Once finished, the dos window displays new results.  The echoing commands is just a bothersome thing.  Any other suggestions on how to get rid of this?????

Thanks,
Kendal
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 11946597
If you are using 'ExecuteAndWaitForCompletion ()', change the 'CreateProcess()' call to read

   bRes    =   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, // <---!
                                   NULL,
                                   NULL,
                                   &si,
                                   &pi
                               );

and you should get rid of the problem.
0
 

Author Comment

by:gvector1
ID: 11996497
Thanks jkr,
Once again you have come to my rescue.  That worked great.  

Thanks again,
Kendal
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

706 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

15 Experts available now in Live!

Get 1:1 Help Now