By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

FTP Check for successful status

100+
P: 121
I have this code to shell out to FTP and run a script. It waits for the script to end and then proceeds wiht the rest of the code.

However, I need to update it so that it returns an error message if any one of the steps don't finish correctly. (i.e. if the PW is bad).

Thanks for any help that could be provided.


Code:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function OpenProcess Lib "kernel32" _
  4. (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
  5. ByVal dwProcessId As Long) As Long
  6.  
  7. Private Declare Function GetExitCodeProcess Lib "kernel32" _
  8. (ByVal hProcess As Long, lpExitCode As Long) As Long
  9.  
  10. Private Const STATUS_PENDING = &H103&
  11. Private Const PROCESS_QUERY_INFORMATION = &H400
  12.  
  13. Public Function ShellandWait(ExeFullPath As String, _
  14. Optional TimeOutValue As Long = 0) As Boolean
  15.  
  16.     Dim lInst As Long
  17.     Dim lStart As Long
  18.     Dim lTimeToQuit As Long
  19.     Dim sExeName As String
  20.     Dim lProcessId As Long
  21.     Dim lExitCode As Long
  22.     Dim bPastMidnight As Boolean
  23.  
  24.     On Error GoTo ErrorHandler
  25.  
  26.     lStart = CLng(Timer)
  27.     sExeName = ExeFullPath
  28.  
  29.     'Deal with timeout being reset at Midnight
  30.     If TimeOutValue > 0 Then
  31.         If lStart + TimeOutValue < 86400 Then
  32.             lTimeToQuit = lStart + TimeOutValue
  33.         Else
  34.             lTimeToQuit = (lStart - 86400) + TimeOutValue
  35.             bPastMidnight = True
  36.         End If
  37.     End If
  38.  
  39.     lInst = Shell(sExeName, vbMinimizedNoFocus)
  40.  
  41. lProcessId = OpenProcess(PROCESS_QUERY_INFORMATION, False, lInst)
  42.  
  43.     Do
  44.         Call GetExitCodeProcess(lProcessId, lExitCode)
  45.         DoEvents
  46.         If TimeOutValue And Timer > lTimeToQuit Then
  47.             If bPastMidnight Then
  48.                  If Timer < lStart Then Exit Do
  49.             Else
  50.                  Exit Do
  51.             End If
  52.     End If
  53.     Loop While lExitCode = STATUS_PENDING
  54.  
  55.     ShellandWait = True
  56.  
  57. ErrorHandler:
  58. ShellandWait = False
  59. Exit Function
  60. End Function
  61.  
  62. Function FTP_CODE()
  63. Dim FTP_SCR As String
  64.  
  65. FTP_SCR = "C:\DLU\SYSTEM\FTP\TEST.scr"
  66. Call ShellandWait("ftp.exe -s:" & FTP_SCR, 1000000)
  67. MsgBox "Process Completed"
  68. Kill "C:\DLU\SYSTEM\FTP\TEST.txt"
  69. End Function
Apr 19 '07 #1
Share this Question
Share on Google+
3 Replies


100+
P: 121
Does anybody have any ideas they could share, or could they point me in the direction of where I could get some ideas.
Apr 19 '07 #2

P: 1
Hi Johnson
Could u please explain the contents of the function" shellANDWait" to me.. i m new to vb and have to edit one code and i'm facing some difficulty in understanding this code..the person has used the same true copy of the function...

Kindly help as u have used it urself

Thanks
Vinni
May 18 '07 #3

Expert 5K+
P: 8,434
I wonder whether FTP sets ERRORLEVEL. If so, you might be able to make use of that. Something of an antiquated concept perhaps, but hey, if it works... :)
May 18 '07 #4

Post your reply

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