Results 1 to 3 of 3

Thread: VBSFTP

  1. #1
    Join Date
    Dec 1969

    Default VBSFTP

    I am calling FTP file from vbs batch. I am trying to write error handling for the FTP server, for the following case<BR>Case one: the log in fail/pass<BR>Case two: FTP servers address wrong<BR>Case three: Everything is okay and the FTP completed uccessfully.<BR>and ect..<BR>I used the method for returning value and if it is Zero thing as worked fine. If not it FTP did not work but after I checked I found that it always return Zero no matter what is the out come. I am attacking the code any help will be appreciated<BR><BR>Thanks<BR><BR>Sub sendFTP()<BR> <BR> dim intReturn<BR> <BR> Dim oShell<BR> set oShell = createobject("Wscript.shell")<BR> intReturn = oShell.Run("ftp -s:""FTP file path""",,true) &#039; Run ftp script to send files<BR> <BR> if (Err.number &#060;&#062; 0) then<BR> <BR> Call report("error occurred", Err.number)<BR> Err.Clear<BR> Else<BR> if intReturn =0 then <BR> Call report("error occurred", Err.number)<BR> else<BR> Call report("completed successfully", Err.number)<BR> end if<BR> End if<BR> on Error goto 0<BR> msgbox intReturn<BR>End Sub<BR>

  2. #2
    Join Date
    Dec 1969

    Default Don't an error would be generated

    FTP is a separate executable. I think you&#039;ll have to direct the output to a text file and read that file looking for problems.<BR><BR>ftp -s :ftp.txt &#062;&#062;c: empftpoutput.txt

  3. #3
    Join Date
    Dec 1969

    Default Yes building on Egg's

    answer..You can do this in a nice DOS script(i.e. - .bat,.cmd) script.<BR><BR>So put your code in a text file and save it as say &#039;testftp.bat&#039; like this<BR><BR> ftp -nv yourFTPserveraddress &#060; ftp.txt &#062;&#062; c: empftpoutput.txt<BR><BR>Then you have to search for a particular error and check errorlevel like<BR><BR> FIND "some error text" &#060; c: empftpoutput.txt &#062; nul<BR> IF NOT ERRORLEVEL 1 GOTO FTP_ERROR<BR><BR> :FTP_ERROR<BR> ...you have an FTP error so what do you want to do<BR><BR>Also, if you have lots of errors you want to check you can use environmental variables to make your life a lot easier.<BR><BR>SET LOG_FILE = c: empftpoutput.txt <BR><BR>Then you just reference %LOG_FILE% anywhere you want to reference your path/filename instead of repeating it.<BR><BR>So you might end up with a final script that looks something like this:<BR><BR>SET LOG_FILE = c: empftpoutput.txt<BR>SET FTP_COMMANDS = c:ftp.txt <BR><BR>echo Starting FTP...... &#062; %LOG_FILE%<BR>FTP -nv yourFTPserveraddress &#060; %FTP_COMMANDS% &#062;&#062; %LOG_FILE%<BR><BR>FIND "some error text" &#060; %LOG_FILE% &#062; nul<BR>IF NOT ERRORLEVEL 1 GOTO FTP_ERROR<BR><BR>GOTO END_SCRIPT<BR><BR>:FTP_ERROR<BR>echo An error occurred in the FTP... &#062;&#062; %LOG_FILE%<BR>...you can put anything else you like in here OR do something else in case of error<BR>:END_SCRIPT<BR><BR>There are so many things you can do with some creative scripting. ; )<BR><BR>I hope that helps. <BR><BR>Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts