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: - Public Sub FTP_Shell(SCR_FILE As String)
-
-
Dim FTP_Task As Long, ret As Long, FTP_Handle As Long
-
Dim FTP_PROCESS As String
-
Dim stSysDir As String
-
stSysDir = Environ$("COMSPEC")
-
stSysDir = Left$(stSysDir, Len(stSysDir) - Len(Dir(stSysDir)))
-
-
FTP_PROCESS = CreateProcessA(sNull, p_Path, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)
-
-
FTP_Task = Shell(stSysDir & "ftp.exe -s:" & stSCRFile, vbNormalFocus)
-
FTP_Handle = OpenProcess(FTP_PROCESS, False, FTP_Task)
-
-
ret = WaitForSingleObject(FTP_Handle, INFINITE)
-
ret = CloseHandle(FTP_Handle)
-
-
End Sub
-
-
Function TEST_FTP_FILES()
-
-
Call FTP_Shell("C:\DLU\System\FTP\Test_FTP.scr")
-
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.
14 2580
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.
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: -
Private Sub Command1_Click()
-
Testing
-
End Sub
2. Add Module to your project and put this code in it: -
Option Explicit
-
-
Private Type STARTUPINFO
-
cb As Long
-
lpReserved As String
-
lpDesktop As String
-
lpTitle As String
-
dwX As Long
-
dwY As Long
-
dwXSize As Long
-
dwYSize As Long
-
dwXCountChars As Long
-
dwYCountChars As Long
-
dwFillAttribute As Long
-
dwFlags As Long
-
wShowWindow As Integer
-
cbReserved2 As Integer
-
lpReserved2 As Long
-
hStdInput As Long
-
hStdOutput As Long
-
hStdError As Long
-
End Type
-
-
Private Type PROCESS_INFORMATION
-
hProcess As Long
-
hThread As Long
-
dwProcessId As Long
-
dwThreadID As Long
-
End Type
-
-
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
-
hHandle As Long, ByVal dwMilliseconds As Long) As Long
-
-
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
-
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
-
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
-
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
-
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
-
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
-
PROCESS_INFORMATION) As Long
-
-
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
-
hObject As Long) As Long
-
-
Private Const NORMAL_PRIORITY_CLASS = &H20&
-
Private Const INFINITE = -1&
-
-
-
-
-
Public Sub ExecCmd(cmdline$)
-
Dim proc As PROCESS_INFORMATION
-
Dim start As STARTUPINFO
-
Dim ReturnValue As Integer
-
-
' Initialize the STARTUPINFO structure:
-
start.cb = Len(start)
-
-
' Start the shelled application:
-
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
-
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
-
-
' Wait for the shelled application to finish:
-
Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
Loop Until ReturnValue <> 258
-
-
ReturnValue = CloseHandle(proc.hProcess)
-
End Sub
-
-
Sub Testing()
-
ExecCmd "NOTEPAD.EXE"
-
'ExecCmd "net send /domain:NYGISW517628 Hello"
-
MsgBox "Process Finished"
-
End Sub
3. Run application and press Command1 button.
Good Luck.
Maybe you will have any use of my code:
1. On VB Form put a Command Button and put this code in it: -
Private Sub Command1_Click()
-
Testing
-
End Sub
2. Add Module to your project and put this code in it: -
Option Explicit
-
-
Private Type STARTUPINFO
-
cb As Long
-
lpReserved As String
-
lpDesktop As String
-
lpTitle As String
-
dwX As Long
-
dwY As Long
-
dwXSize As Long
-
dwYSize As Long
-
dwXCountChars As Long
-
dwYCountChars As Long
-
dwFillAttribute As Long
-
dwFlags As Long
-
wShowWindow As Integer
-
cbReserved2 As Integer
-
lpReserved2 As Long
-
hStdInput As Long
-
hStdOutput As Long
-
hStdError As Long
-
End Type
-
-
Private Type PROCESS_INFORMATION
-
hProcess As Long
-
hThread As Long
-
dwProcessId As Long
-
dwThreadID As Long
-
End Type
-
-
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
-
hHandle As Long, ByVal dwMilliseconds As Long) As Long
-
-
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
-
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
-
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
-
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
-
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
-
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
-
PROCESS_INFORMATION) As Long
-
-
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
-
hObject As Long) As Long
-
-
Private Const NORMAL_PRIORITY_CLASS = &H20&
-
Private Const INFINITE = -1&
-
-
-
-
-
Public Sub ExecCmd(cmdline$)
-
Dim proc As PROCESS_INFORMATION
-
Dim start As STARTUPINFO
-
Dim ReturnValue As Integer
-
-
' Initialize the STARTUPINFO structure:
-
start.cb = Len(start)
-
-
' Start the shelled application:
-
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
-
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
-
-
' Wait for the shelled application to finish:
-
Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
Loop Until ReturnValue <> 258
-
-
ReturnValue = CloseHandle(proc.hProcess)
-
End Sub
-
-
Sub Testing()
-
ExecCmd "NOTEPAD.EXE"
-
'ExecCmd "net send /domain:NYGISW517628 Hello"
-
MsgBox "Process Finished"
-
End Sub
3. Run application and press Command1 button.
Good Luck.
Thanks so much. I will try it later and hopefully it will work.
iburyak 1,017
Recognized Expert Top Contributor
Let me know how it goes.... :)
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
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 - Option Explicit
-
-
Private Type STARTUPINFO
-
cb As Long
-
lpReserved As String
-
lpDesktop As String
-
lpTitle As String
-
dwX As Long
-
dwY As Long
-
dwXSize As Long
-
dwYSize As Long
-
dwXCountChars As Long
-
dwYCountChars As Long
-
dwFillAttribute As Long
-
dwFlags As Long
-
wShowWindow As Integer
-
cbReserved2 As Integer
-
lpReserved2 As Long
-
hStdInput As Long
-
hStdOutput As Long
-
hStdError As Long
-
End Type
-
-
Private Type PROCESS_INFORMATION
-
hProcess As Long
-
hThread As Long
-
dwProcessId As Long
-
dwThreadID As Long
-
End Type
-
-
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
-
hHandle As Long, ByVal dwMilliseconds As Long) As Long
-
-
Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
-
lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
-
lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
-
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
-
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
-
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
-
PROCESS_INFORMATION) As Long
-
-
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
-
hObject As Long) As Long
-
-
Private Const NORMAL_PRIORITY_CLASS = &H20&
-
Private Const INFINITE = -1&
-
-
-
-
-
Public Sub ExecCmd(cmdline$, FTP_SCR As String)
-
Dim proc As PROCESS_INFORMATION
-
Dim start As STARTUPINFO
-
Dim ReturnValue As Integer
-
-
' Initialize the STARTUPINFO structure:
-
start.cb = Len(start)
-
-
' Start the shelled application:
-
ReturnValue = Shell("ftp.exe -s:" & FTP_SCR, vbNormalFocus)
-
-
-
' Wait for the shelled application to finish:
-
Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
Loop Until ReturnValue = 226
-
-
ReturnValue = CloseHandle(proc.hProcess)
-
End Sub
-
-
Sub Testing(FTP_SCR As String)
-
Dim ROOT_DRIVE As String
-
-
ROOT_DRIVE = DLookup("[ROOT_FOLDER]", "[CONFIG - ROOT FOLDER]")
-
ExecCmd "FTP.EXE", FTP_SCR
-
'ExecCmd "net send /domain:NYGISW517628 Hello"
-
Kill "c:\DLU\System\FTP\TEST.jpg"
-
MsgBox "Process Finished"
-
End Sub
-
-
Function TEST_FTP_FILES()
-
Dim ROOT_DRIVE As String
-
Dim FTP_SCR As String
-
-
-
ROOT_DRIVE = DLookup("[ROOT_FOLDER]", "[CONFIG - ROOT FOLDER]")
-
FTP_SCR = ROOT_DRIVE & ":\DLU\System\FTP\Test_FTP.scr"
-
Call Testing(FTP_SCR)
-
-
End Function
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.
iburyak 1,017
Recognized Expert Top Contributor
In my code I have this: - Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
Loop Until ReturnValue <> 258
And you have this: - Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
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.
Right- so when I run it with your code: - Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
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: - Do
-
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
-
DoEvents
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 finished running, I
want to do more stuff *condition* on the fact that the shell script
has finished running, inside the same python script.
The only way I can think of is to fork a process and then call the
|
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
--------------------------------------------------------------------------------
Hello,
I have a very simple problem but cannot seem to figure it out. I have a
very simple php script that sends a test email to myself. When I debug
it in PHP designer, it works with no problems, I get the test email. If
|
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 works to run DTSRun from the command line without typing in the directory
as c:\program files\microsoft sql server\80\tools\binn is in the 'path' environmen
variable, so it can be found
What is the equivalent in C# of VB.NET's Shell, given that...
|
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 with the "print"-verb.
This works for me. However, I need to handle the case when a printing
application
doesnt't quit in a given timespan (for example a password-protected
word-document). So I've tried the following:
|
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 attach this script
files and inq files. I cant understand this error. Please suggest me.
You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online.
Plz....Plz..Plz...
| |
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 entered from the keyboard. I launch
this utility (through a batch file) programmatically in a command-shell
process through the Process object with no window (i.e.
myProcess.StartInfo.CreateNoWindow = true). I have re-directed the
StandardInput to a...
|
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
********************************************************
For this teeny job, please refer to:
http://feeds.reddit.com/feed/8fu/?o=25
|
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 I'm not sure where I'm going wrong.
This is the code as I have it now:
Public Sub FTP_Shell(SCR_FILE As String)
Dim FTP_Task As Long, ret As Long, FTP_Handle As Long
Dim FTP_PROCESS As String
|
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
http://xahlee.org/emacs/elisp_perl_wrapper.html
plain text version follows.
-------------------------------------
Elisp Wrapper For Perl Scripts
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |