Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Error handling FTP automation

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1789
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Error handling FTP automation
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Error handling FTP automation - 1/5/2005 7:20:02 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Hi all,

I made a function to automate the FTP transfer of files



      


This works perfectly as long as there aren't any problems during the FTP-ing.
Does anybody know how I can handle the FTP errors? Or else maybe log them?

Thanks in advance!
 
 
Post #: 1
 
 Re: Error handling FTP automation - 1/5/2005 11:21:26 PM   
  drbelden

 

Posts: 109
Score: 0
Joined: 12/21/2004
From: USA
Status: offline
Use
       to trap the error and log it.

(in reply to Zifter)
 
 
Post #: 2
 
 Re: Error handling FTP automation - 1/6/2005 2:57:47 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
I appreciate you trying to help, but with
       I can only trap the scripting errors, the problem I'm confronted with is when an error occurs during the execution of the FTP commands.

Thanks anyway for taking the time to read and reply to this post.

Other suggestions? Anyone?

(in reply to Zifter)
 
 
Post #: 3
 
 Re: Error handling FTP automation - 1/6/2005 3:05:30 AM   
  tnoonan

 

Posts: 364
Score: 0
Joined: 12/14/2004
From:
Status: offline
Check out this script. May have what your looking for.
Writes results at the end and echo's them.

http://www.spoogenet.com/index.php?module=article&view=8&5cbaa9d36385e275f0a415eb9b827618=1c284633aceabe9d4c4f24f7407fb974

(in reply to Zifter)
 
 
Post #: 4
 
 Re: Error handling FTP automation - 1/6/2005 9:27:40 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Well, actually, the script there does almost exactly the same as mine.
As extra it echoes the contents of the file being transferred, but that's not really what I need.

I should find a way to catch errors during FTP transfers or to log each FTP step and loop through the log file entries afterwards scanning for errors (or something like that...)

Thanks anyway for providing the link.

I hope someone can help me in my search for a solution

(in reply to Zifter)
 
 
Post #: 5
 
 Re: Error handling FTP automation - 1/6/2005 11:18:21 PM   
  drbelden

 

Posts: 109
Score: 0
Joined: 12/21/2004
From: USA
Status: offline
Sorry, I don't do much with FTP from the command prompt. Does it give you an error in the command window when there is an error? If so you could redirect your output to a file
       then search the file.txt for indications of the error.

I don't know if this is a workable solution for you, but I hope so.

(in reply to Zifter)
 
 
Post #: 6
 
 Re: Error handling FTP automation - 1/6/2005 11:53:47 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
drbelden, no need to apologize, I'm very glad there are people that are willing to help. Nobody knows everything.

And I think your last suggestion is getting close to something I can work with.
Unfortunately, I don't get it to work.

I think you misplaced the file redirecting (correct me if I'm wrong), but I think it should go right after the "strInstructions" in stead of after "True". Like this:

      but even that doesn't seem to work...

What am I doing wrong?

(in reply to Zifter)
 
 
Post #: 7
 
 Re: Error handling FTP automation - 1/7/2005 3:09:23 AM   
  tnoonan

 

Posts: 364
Score: 0
Joined: 12/14/2004
From:
Status: offline
Cant you do like this

if Err.Number=0 Then
With objFso
With .CreateTextFile(strInstructions, True)
.WriteLine "open " & strHost
.WriteLine "user " & strUser
.WriteLine strPassword
.WriteLine "lcd C:\FTP_Out"
.WriteLine "cd \FTP_In"
.WriteLine "put file.ext"
.WriteLine "close"
.WriteLine "quit"
.Close
End With
If Err.Number <> 0 then
outFile.writeline (Now & vbTab & Err.Number & ":" Err.Description)
Err.Clear

(in reply to Zifter)
 
 
Post #: 8
 
 Re: Error handling FTP automation - 1/9/2005 7:04:35 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
I'm sorry tnoonan, but that will only trap errors during the creation and filling of the file.

It's not until the objShell.run that these FTP commands are executed. It is during this process, I would like to catch/monitor errors.

I think drbelden's suggestion about piping the output to a file would be an acceptable solution...if I can get it to work...

(in reply to Zifter)
 
 
Post #: 9
 
 Re: Error handling FTP automation - 1/25/2005 5:06:02 AM   
  dgrigsby

 

Posts: 1
Score: 0
Joined: 1/25/2005
From:
Status: offline
I believe the answer lies in .exec vs .run;
Article at http://www.microsoft.com/technet/community/columns/scripts/sg1002.mspx goes into great depths about differences and how to get the error information from the object as well.

Best Regards,

David.

(in reply to Zifter)
 
 
Post #: 10
 
 Re: Error handling FTP automation - 1/25/2005 4:56:21 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
The following code:
=========================================================================================
Set shell = CreateObject("WScript.Shell")
Set shellExec = shell.Exec("%comspec% /c %windir%\system32\ftp.exe -i -n -s:test11.txt")
Do Until shellExec.StdOut.AtEndOfStream
temp = shellExec.StdOut.ReadLine()
WScript.Echo temp
Loop
=========================================================================================

produced the following results:
=========================================================================================
open server
user token


get ntldr
ntldr: The system cannot find the file specified.
close
quit
=========================================================================================

with test11.txt haing the following content:

=========================================================================================
open server
user token
<password>
get ntldr
close
quit
=========================================================================================


In order to capture errors within the ftp session, you have to know the format of the error message. Above is one example. Also noted that depends on the FTP server used, DOS filesystem path convention might not be valid (most of which use Unix style filesystem path). In your code, the root "/" is usually where the user at after logging into the system which is determined by the ftp admin and how it is configured. Usually when the ftp is configured to use ftproot as the relative root for the user, they can't go beyond the root, eg: c:\ftproot, so specifying c:\ntldr won't be successful. Instead, in order for get ntdlr to be successful in the above case, c:\ftproot\ntldr must exist.

Hope this helps

(in reply to Zifter)
 
 
Post #: 11
 
 Re: Error handling FTP automation - 1/26/2005 12:33:41 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Thanks token and dgrigsby!
Altough I still have to iterate through the output to find the errors, it is an acceptable solution.
Thanks again, I consider this topic as closed.

(in reply to Zifter)
 
 
Post #: 12
 
 Re: Error handling FTP automation - 1/26/2005 2:10:42 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
One way to find out exactly what happen after each command is issued could be that you write to the file one line at a time then execute the ftp command; therefore, there will only be one otuput captured by the exec object, then you do something about the output, and loop through the 10 or so steps in adding the file content.

(in reply to Zifter)
 
 
Post #: 13
 
 Re: Error handling FTP automation - 2/3/2005 6:28:13 AM   
  Cobalt

 

Posts: 17
Score: 0
Joined: 2/3/2005
From:
Status: offline
Using the FTP.EXE that ships with windows to automate FTP can be problematic because you have to deal with the STDIO streams.

The solution that I had to this problem was to write a COM object which uses the API's to actually handle the transfer.

It's available on http://www.pcsupport.net under the Projects menu if you are still interested. Free to a good home. :)

(in reply to Zifter)
 
 
Post #: 14
 
 Re: Error handling FTP automation - 3/29/2005 1:22:09 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi All,
I am kind of a noob with VB.
I am trying to backup a file from my website via ftp to another serverr after i have been hacked and all the website db was deleted. I am using this script (thanks Zifter - for the script)
I have a few questions on it though:
there is a line: strInstructions = "C:\Instructions.ftp" - WHAT does this file contain inside?
I have a script that copies the mdn file from a main root folder to the backup folder. And now i want that the file from the backup folder will be uploaded to the FTP.
For some reason this file is 10MB and it is only uploading 80k.
I believe and understand that it is since the file is not being uploaded from the correct place.
In this scrip where can i change that the file will be uploaded form a certaind directory to the FTP?
Second:
I have removed these 2 line:
.WriteLine "lcd C:\FTP_Out"
.WriteLine "cd \FTP_In"
i understand that these files are onces you are logged to the ftp and i dont need them since i am uploading to the main root.
Can anybody help me pls thanks

(in reply to Zifter)
 
 
Post #: 15
 
 Re: Error handling FTP automation - 3/29/2005 1:57:03 AM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Hey buffi,

The file "C:\Instructions.ftp" is first created with the following statement "objFso.CreateTextFile(strInstructions, True)"
Then it gets filled with the instructions I wanted to do in FTP.
Each ".WriteLine" statement adds a line to this file, in the order you would enter them when doing FTP from a command line.
In other words, instead of typing each command manualy on a command line FTP, I write them first to a file and then let the command FTP gets his instructions line by line from this file
(on a command line type "ftp -?" and check the -s flag)
The "lcd" FTP command changes the local working directory
The "cd" FTP command changes the remote working directory
If I understand your situation correctly, you should use the "lcd" command to tell the FTP server where to get the file, and you can leave the "cd" command out, since you want the file to get uploaded to the route.

Note: Alternatively you can leave both "lcd" and "cd" statements out and make sure your "put" (or "get") command includes complete paths to the files

HTH

(in reply to Zifter)
 
 
Post #: 16
 
 Re: Error handling FTP automation - 3/29/2005 5:37:00 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
it still amazes me that there isnt a builtin functionality for ftp in vbs, you have http(s) but not ftp.

anyways, that said,

here is how i trap exit status from external programs


      

(in reply to Zifter)
 
 
Post #: 17
 
 Re: Error handling FTP automation - 3/29/2005 12:17:23 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
If you could post your code, we could probably take a look at it to determine why only 80K was uploaded instead of 10MB.

(in reply to Zifter)
 
 
Post #: 18
 
 Re: Error handling FTP automation - 3/29/2005 7:14:50 PM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
HI Zifter,
Thanks for the explanation. I understand it better now. Although I saw that the 10MB is being uploaded only if it on the same directory as where the scripts is. It is uploading it now but i will check on the other issue as well.
I have another small question. I want to rename the file backup.mdb to something with the date so when each day it will upload the file to the ftp with different names example: backup300305.mdb then the next day it will upload it with the name backup310305.mdb etc.
I mean with the date of that certain day.
Is it possible?
I know i only need to rename the file with the date code.
Can someone pass it on pls

Thanks alot for the greathelp

Buffi

(in reply to Zifter)
 
 
Post #: 19
 
 Re: Error handling FTP automation - 3/29/2005 10:40:00 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
You can give a file being transfered with FTP any name you want.
Like this:
Put <local path>\OriginalFile.ext <remote path>\NewName.ext
The file "OriginalFile.ext" will be transfered to the remote path with the name "NewName.ext"

In order to add the current date to the file name, you'll have to format the return value of the Now() function or the Date() function and concatenate it (with &) to the filename.

In this topic I show a function I use to format the result of the Now() function.

Post the relevant part of your code if you need more specific help.

HTH

(in reply to Zifter)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Error handling FTP automation Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts