473,480 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help writing a process for FTP Shell Function

121 New Member
I posted this in the Access thread, but seeing as how this is a VB problem, I thought this might be the better place

I have a code to FTP files to a server, using a script FTP.scr.

I need to wait until the FTP completes before proceeding to the next code. So far every process I have written keeps failing, and I'm not sure where I'm going wrong.

This is the code as I have it now:

Expand|Select|Wrap|Line Numbers
  1. Public Sub FTP_Shell(SCR_FILE As String)
  2.  
  3. Dim FTP_Task As Long, ret As Long, FTP_Handle As Long
  4. Dim FTP_PROCESS As String
  5. Dim stSysDir As String
  6.     stSysDir = Environ$("COMSPEC")
  7.     stSysDir = Left$(stSysDir, Len(stSysDir) - Len(Dir(stSysDir)))
  8.  
  9.     FTP_PROCESS = CreateProcessA(sNull, p_Path, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)
  10.  
  11.     FTP_Task = Shell(stSysDir & "ftp.exe -s:" & stSCRFile, vbNormalFocus)
  12.     FTP_Handle = OpenProcess(FTP_PROCESS, False, FTP_Task)
  13.  
  14.     ret = WaitForSingleObject(FTP_Handle, INFINITE)
  15.     ret = CloseHandle(FTP_Handle)
  16.  
  17. End Sub
  18.  
  19. Function TEST_FTP_FILES()
  20.  
  21. Call FTP_Shell("C:\DLU\System\FTP\Test_FTP.scr")
  22. End Function
I would really appreciate it if anyone had either a link ot a good resource on writing a process, or if anyone can help me wiht what this process would/should look like.

I haven't really written processes before - this is a new area of vb for me.

Thanks for any help anyone can provide.
Apr 12 '07 #1
14 2545
tifoso
41 New Member
I had the same issue, the quick and dirty solution is send a dummy file after the one u r waiting for that way u can put a while loop /doevents on the dummy file and it won't happen until your main file has completed.

i.e. add to the scr lines as below of course the dummy file has to be at the ftp site
...
get good_file
get dummy_file
...

It is crude but I had a deadline and that is how it worked , there are more elegant ways but same as you I had to use a script as a requirement, since it was generated from some other place in the code.
Apr 12 '07 #2
iburyak
1,017 Recognized Expert Top Contributor
Maybe you will have any use of my code:


1. On VB Form put a Command Button and put this code in it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Testing
  3. End Sub
2. Add Module to your project and put this code in it:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type STARTUPINFO
  4.          cb As Long
  5.          lpReserved As String
  6.          lpDesktop As String
  7.          lpTitle As String
  8.          dwX As Long
  9.          dwY As Long
  10.          dwXSize As Long
  11.          dwYSize As Long
  12.          dwXCountChars As Long
  13.          dwYCountChars As Long
  14.          dwFillAttribute As Long
  15.          dwFlags As Long
  16.          wShowWindow As Integer
  17.          cbReserved2 As Integer
  18.          lpReserved2 As Long
  19.          hStdInput As Long
  20.          hStdOutput As Long
  21.          hStdError As Long
  22.       End Type
  23.  
  24.       Private Type PROCESS_INFORMATION
  25.          hProcess As Long
  26.          hThread As Long
  27.          dwProcessId As Long
  28.          dwThreadID As Long
  29.       End Type
  30.  
  31.       Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  32.          hHandle As Long, ByVal dwMilliseconds As Long) As Long
  33.  
  34.       Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
  35.          lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  36.          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  37.          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  38.          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  39.          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  40.          PROCESS_INFORMATION) As Long
  41.  
  42.       Private Declare Function CloseHandle Lib "kernel32" (ByVal _
  43.          hObject As Long) As Long
  44.  
  45.       Private Const NORMAL_PRIORITY_CLASS = &H20&
  46.       Private Const INFINITE = -1&
  47.  
  48.  
  49.  
  50.  
  51.       Public Sub ExecCmd(cmdline$)
  52.          Dim proc As PROCESS_INFORMATION
  53.          Dim start As STARTUPINFO
  54.          Dim ReturnValue As Integer
  55.  
  56.          ' Initialize the STARTUPINFO structure:
  57.          start.cb = Len(start)
  58.  
  59.          ' Start the shelled application:
  60.          ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
  61.             NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
  62.  
  63.          ' Wait for the shelled application to finish:
  64.          Do
  65.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  66.             DoEvents
  67.          Loop Until ReturnValue <> 258
  68.  
  69.          ReturnValue = CloseHandle(proc.hProcess)
  70.       End Sub
  71.  
  72.       Sub Testing()
  73.          ExecCmd "NOTEPAD.EXE"
  74.          'ExecCmd "net send /domain:NYGISW517628 Hello"
  75.          MsgBox "Process Finished"
  76.       End Sub
3. Run application and press Command1 button.

Good Luck.
Apr 12 '07 #3
JHNielson
121 New Member
Maybe you will have any use of my code:


1. On VB Form put a Command Button and put this code in it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Testing
  3. End Sub
2. Add Module to your project and put this code in it:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type STARTUPINFO
  4.          cb As Long
  5.          lpReserved As String
  6.          lpDesktop As String
  7.          lpTitle As String
  8.          dwX As Long
  9.          dwY As Long
  10.          dwXSize As Long
  11.          dwYSize As Long
  12.          dwXCountChars As Long
  13.          dwYCountChars As Long
  14.          dwFillAttribute As Long
  15.          dwFlags As Long
  16.          wShowWindow As Integer
  17.          cbReserved2 As Integer
  18.          lpReserved2 As Long
  19.          hStdInput As Long
  20.          hStdOutput As Long
  21.          hStdError As Long
  22.       End Type
  23.  
  24.       Private Type PROCESS_INFORMATION
  25.          hProcess As Long
  26.          hThread As Long
  27.          dwProcessId As Long
  28.          dwThreadID As Long
  29.       End Type
  30.  
  31.       Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  32.          hHandle As Long, ByVal dwMilliseconds As Long) As Long
  33.  
  34.       Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
  35.          lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  36.          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  37.          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  38.          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  39.          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  40.          PROCESS_INFORMATION) As Long
  41.  
  42.       Private Declare Function CloseHandle Lib "kernel32" (ByVal _
  43.          hObject As Long) As Long
  44.  
  45.       Private Const NORMAL_PRIORITY_CLASS = &H20&
  46.       Private Const INFINITE = -1&
  47.  
  48.  
  49.  
  50.  
  51.       Public Sub ExecCmd(cmdline$)
  52.          Dim proc As PROCESS_INFORMATION
  53.          Dim start As STARTUPINFO
  54.          Dim ReturnValue As Integer
  55.  
  56.          ' Initialize the STARTUPINFO structure:
  57.          start.cb = Len(start)
  58.  
  59.          ' Start the shelled application:
  60.          ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
  61.             NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
  62.  
  63.          ' Wait for the shelled application to finish:
  64.          Do
  65.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  66.             DoEvents
  67.          Loop Until ReturnValue <> 258
  68.  
  69.          ReturnValue = CloseHandle(proc.hProcess)
  70.       End Sub
  71.  
  72.       Sub Testing()
  73.          ExecCmd "NOTEPAD.EXE"
  74.          'ExecCmd "net send /domain:NYGISW517628 Hello"
  75.          MsgBox "Process Finished"
  76.       End Sub
3. Run application and press Command1 button.

Good Luck.

Thanks so much. I will try it later and hopefully it will work.
Apr 12 '07 #4
iburyak
1,017 Recognized Expert Top Contributor
Let me know how it goes.... :)
Apr 12 '07 #5
JHNielson
121 New Member
So I put the code in and ran it - and all that happens is it opens up Notepad and says "process finished". I'm not sure where I call on my script I have written, or where I put the process information in.


Thanks for your generous help
Apr 16 '07 #6
JHNielson
121 New Member
So here is the code I have. I got it to do everything I want it to do, expect now it doesn't seem to pick up the successful transfer return value. It waits but never stops.

I tested an FTP connection manually, and when it was done successfully transferring, the number at the beginning of the line was 226. I assume that is th e return value it should be looking for. That is what I set it to, but it doesn't ever stop the program even after the FTP window has been closed.

Any help would be great. I don't wan to be a pest about this, but I'm down to the wire and this has been plaguing me for weeks.


Thanks again


Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Type STARTUPINFO
  4.          cb As Long
  5.          lpReserved As String
  6.          lpDesktop As String
  7.          lpTitle As String
  8.          dwX As Long
  9.          dwY As Long
  10.          dwXSize As Long
  11.          dwYSize As Long
  12.          dwXCountChars As Long
  13.          dwYCountChars As Long
  14.          dwFillAttribute As Long
  15.          dwFlags As Long
  16.          wShowWindow As Integer
  17.          cbReserved2 As Integer
  18.          lpReserved2 As Long
  19.          hStdInput As Long
  20.          hStdOutput As Long
  21.          hStdError As Long
  22.       End Type
  23.  
  24.       Private Type PROCESS_INFORMATION
  25.          hProcess As Long
  26.          hThread As Long
  27.          dwProcessId As Long
  28.          dwThreadID As Long
  29.       End Type
  30.  
  31.       Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  32.          hHandle As Long, ByVal dwMilliseconds As Long) As Long
  33.  
  34.       Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
  35.          lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
  36.          lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
  37.          ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
  38.          ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
  39.          lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  40.          PROCESS_INFORMATION) As Long
  41.  
  42.       Private Declare Function CloseHandle Lib "kernel32" (ByVal _
  43.          hObject As Long) As Long
  44.  
  45.       Private Const NORMAL_PRIORITY_CLASS = &H20&
  46.       Private Const INFINITE = -1&
  47.  
  48.  
  49.  
  50.  
  51.       Public Sub ExecCmd(cmdline$, FTP_SCR As String)
  52.          Dim proc As PROCESS_INFORMATION
  53.          Dim start As STARTUPINFO
  54.          Dim ReturnValue As Integer
  55.  
  56.          ' Initialize the STARTUPINFO structure:
  57.          start.cb = Len(start)
  58.  
  59.          ' Start the shelled application:
  60.          ReturnValue = Shell("ftp.exe -s:" & FTP_SCR, vbNormalFocus)
  61.  
  62.  
  63.          ' Wait for the shelled application to finish:
  64.          Do
  65.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  66.             DoEvents
  67.          Loop Until ReturnValue = 226
  68.  
  69.          ReturnValue = CloseHandle(proc.hProcess)
  70.       End Sub
  71.  
  72.       Sub Testing(FTP_SCR As String)
  73.       Dim ROOT_DRIVE As String
  74.  
  75.         ROOT_DRIVE = DLookup("[ROOT_FOLDER]", "[CONFIG - ROOT FOLDER]")
  76.         ExecCmd "FTP.EXE", FTP_SCR
  77.          'ExecCmd "net send /domain:NYGISW517628 Hello"
  78.         Kill "c:\DLU\System\FTP\TEST.jpg"
  79.          MsgBox "Process Finished"
  80.       End Sub
  81.  
  82. Function TEST_FTP_FILES()
  83. Dim ROOT_DRIVE As String
  84. Dim FTP_SCR As String
  85.  
  86.  
  87. ROOT_DRIVE = DLookup("[ROOT_FOLDER]", "[CONFIG - ROOT FOLDER]")
  88. FTP_SCR = ROOT_DRIVE & ":\DLU\System\FTP\Test_FTP.scr"
  89. Call Testing(FTP_SCR)
  90.  
  91. End Function
Apr 17 '07 #7
JHNielson
121 New Member
One more thing, when i set the "Loop return value..." statement to <> 258, the process just finishes without waiting for the file to transfer and the process to end.

When I set it to =226, it never stops.

Thanks, for an help I can get.
Apr 17 '07 #8
iburyak
1,017 Recognized Expert Top Contributor
In my code I have this:

Expand|Select|Wrap|Line Numbers
  1. Do
  2.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  3.             DoEvents
  4. Loop Until ReturnValue <> 258
And you have this:

Expand|Select|Wrap|Line Numbers
  1. Do
  2.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  3.             DoEvents
  4. Loop Until ReturnValue = 226
This code is executed in a loop while it is waiting for Shell command to finish.
Debug this code and check which one you want to use.

I know for sure that mine works and waits for other program to finish and then proceeds with the code correctly. This is why I had a Notepad so you would see that Message box appear only when you close a Notepad symbolizing that other program has finished.

Good Luck.
Apr 17 '07 #9
JHNielson
121 New Member
Right- so when I run it with your code:
Expand|Select|Wrap|Line Numbers
  1. Do
  2.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  3.             DoEvents
  4. Loop Until ReturnValue <> 258
It proceeds through the rest of the code before the FTP finishes. The last process is to move the files from the current directory to a storage directory.
The files get moved before they get sent.


When I use my code:
Expand|Select|Wrap|Line Numbers
  1. Do
  2.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  3.             DoEvents
  4. Loop Until ReturnValue = 226
The rest of the code never finishes.

I'm trying to figure out what is keeping the process from finishing in my code, or from finishing too fast in your code. How do I figure out what the return value should be. Is there a list somewhere or a way to determine this?

Thanks
Apr 17 '07 #10
iburyak
1,017 Recognized Expert Top Contributor
Check this out:

http://msdn2.microsoft.com/en-us/library/ms687032.aspx
Apr 17 '07 #11
JHNielson
121 New Member
Check this out:

http://msdn2.microsoft.com/en-us/library/ms687032.aspx

Thanks - that helped, except for the question of where you get "258" from. what is that number. I thought it was the return value that comes from FTP? How do i verify that is the right number for my system? How do I find the number if it is not?

Am I looking at the wrong place in the code?

Thanks so much for your help. I hate to be such a pest, but I'm down to the wire and have been trying to get this right so long, and I'm so close now!

Thanks again
Apr 17 '07 #12
iburyak
1,017 Recognized Expert Top Contributor
I understand your frastration and I am trying to help as much as I can.
You can probably do following:

Expand|Select|Wrap|Line Numbers
  1. Do
  2.             ReturnValue = WaitForSingleObject(proc.hProcess, 0)
  3.             Debug.print ReturnValue
  4.             DoEvents
  5. Loop Until ReturnValue = 226
You will see all possible return codes and would be able to judge which one to use.

This is how I found my number.... :)

I'll dig my old stuff more.... :)
Apr 17 '07 #13
JHNielson
121 New Member
Great thanks so much! I solved it! Thanks for all your great help!
Apr 18 '07 #14
iburyak
1,017 Recognized Expert Top Contributor
So what was your final solution?
I am so happy that you are finally worked it out..... :)

Good Luck.
Irina.
Apr 18 '07 #15

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

Similar topics

21
13044
by: John Lin | last post by:
Howdy, I want to know how to tell if a forked process is done. Actually, my real question is that I want to run a shell script inside of a python script, and after the shell script has...
8
5442
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
15
1954
by: songie D | last post by:
H If I us Process.Start("DTSRun ...") on a computer that has SQL server installed, it can't fin DTSRun, claiming 'file not found'. Despite this, Shell("DTSRun...") from VB.NET works fine It also...
0
2224
by: henning.friese | last post by:
Hello NG, I'm need to write some code which creates tiff files from various document types (doc, pdf, xls). I want to do this by ShellExecuting (via System.Diagnostics.Process) the doc-files...
1
3690
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
5
5551
by: Mark M | last post by:
I am attempting to use a third party command-line utility (WinDump.exe) to capture network traffic for perfromance analysis. This utility when launched captures network traffic until Ctrl-C is...
0
5517
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
1867
by: JHNielson | last post by:
I have a code to FTP files to a server, using a script FTP.scr. I need to wait until the FTP completes before proceeding to the next code. So far every process I have written keeps failing, and...
0
1238
by: xahlee | last post by:
Here's a little tutorial that lets you write emacs commands for processing the current text selection in emacs in your favorite lang. Elisp Wrapper For Perl Scripts...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7044
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,...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6739
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...
0
6929
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...
1
4779
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...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
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...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.