Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Re: 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 >> Re: Error handling FTP automation
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 Re: Error handling FTP automation - 3/30/2005 1:50:19 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi Zifter,
First I would like to thank you for the time you are taking helping me.
Here is the script i am using

      

Now this scripts takes the file from one folder to the backup folder and from the backup folder it uploads it to the ftp server.
Since i have scheduled it to do it every night it automaticaly deletes the old file with the new file (on the ftp side).
I want the script to take the original file (repsys.mdb) and rename is to repsys+date.mdb and will upload this to the ftp.
for example today it will upload repsys300305.mdb and tomorrow i will want it to upload repsys310305.mdb and so on.
Is it possible???
If so can you please check my scrip and update it - cause i am a reall noob at it.

Regards,
Buffi

(in reply to Zifter)
 
 
Post #: 21
 
 Re: Error handling FTP automation - 3/30/2005 9:19:43 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
I made a few modifications to your script.

First of all, the "Dim" statements are only mandatory if you start your script with "Option Explicit". I think it is good practice to use "Option Explicit" which forces you to declare each variable you use in the script. This way you already prevent type errors with your variables.

Secondly, you don't need to create the FileSystemObject twice (Set objFso = CreateObject("Scripting.FileSystemObject")), once is enough, you can use it until you release it (Set objFso = Nothing)

I added a small piece of code, where the new variables strYear, strMonth and strDay are filled with respectively the current year, month and day.

Finally I changed the "put" command, including the source path of the file to be transferred (so your script doesn't need to be in the same folder as the backup anymore) and concatenating the new variables to the name of the destination file.

I didn't test it, but it should work.

If you still have problems, questions, remarks, ... feel free to post them


      HTH

(in reply to Zifter)
 
 
Post #: 22
 
 Re: Error handling FTP automation - 3/30/2005 10:28:38 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
After rereading your last post, I think I might have misunderstood exactly what you're trying to do.

The previous script I've posted, will still overwrite the file in the "c:\backup" folder each day. Only the file on the FTP server side will have a name with the current date.

The next script will copy the file to the "c:\backup" folder with the new name (with the date) and then transfer that file to the FTP server.
      HTH

(in reply to Zifter)
 
 
Post #: 23
 
 Re: Error handling FTP automation - 3/31/2005 9:13:49 PM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Thanks Ziffer,
I managed to fix it before reading your post, but i will check that script as well.
I managed to fix that issue with the winzip function on one of the scripts posted here before. which zips the file with the current date.
Thanks alot for the help.

(in reply to Zifter)
 
 
Post #: 24
 
 Re: Error handling FTP automation - 4/9/2005 4:34:08 PM   
  pebkacid10t

 

Posts: 2
Score: 0
Joined: 4/9/2005
From:
Status: offline
This is my first attempt at creating a vb script. Many thanks to Zifter as I used much of the code he posted. This script "should" download the most current sdat file from ftp.mcafee.com. However, I have two statements that don't work properly. The first is

objShell.run "%windir%\system32\findstr.exe /r sdat[0-9] files.txt >" & strSdatName

If you omit objShell.run and enter the same command at the dos prompt, it runs flawlessly. Hence, my frustration.

In order to have the code after this point work, it's necessary to run this command at the command line so that sdatname.txt is created.

The next problem is found at

objShell.run "%windir%\system32\ftp.exe -s:" & strControl & strHost

I've gotten this to work once or twice at the command line also while substituting strControl and strHost for their strings. Sometimes it copies the remote file to a local file named close. Regardless, during the execution of the script, it does nothing more than pop up a dos window with the help for the ftp command displayed.

Thanks in advance to anyone who even takes the time to read this post.

Option Explicit

Dim objFso
Dim objShell
Dim strInstructions
Dim strHost
Dim strInstructions2
Dim strInstructions3
Dim strSdatName
Dim strControl

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")

strInstructions = "C:\getdir.txt"
strHost = "ftp.mcafee.com"
strInstructions2 = "C:\ftppart1.txt"
strInstructions3 = "C:\ftppart2.txt"
strSdatName = "C:\sdatname.txt"
strControl = "C:\control.txt"

With objFso
With .CreateTextFile(strInstructions, True)
.WriteLine "open " & strHost
.WriteLine "cd pub/antivirus/superdat/intel/"
.WriteLine "ls . files.txt"
.WriteLine "close"
.WriteLine "quit"
.Close
End With

objShell.run "%windir%\system32\ftp.exe -A -s:" & strInstructions, 1, True

With .CreateTextFile(strInstructions2, True)
.WriteLine "binary"
.WriteLine "prompt n"
.WriteLine "cd pub/antivirus/superdat/intel/"
.WriteLine "get"
.Close
End With

objShell.run "%windir%\system32\findstr.exe /r sdat[0-9] files.txt >" & strSdatName

With .CreateTextFile(strInstructions3, True)
.WriteLine "close"
.WriteLine "quit"
.Close
End With

objShell.run "C:\WINDOWS\system32\command.com /c copy ftppart1.txt+sdatname.txt+ftppart2.txt" & strControl
objShell.run "%windir%\system32\ftp.exe -s:" & strControl & strHost

End With

Set objShell = Nothing
Set objFso = Nothing

(in reply to Zifter)
 
 
Post #: 25
 
 Re: Error handling FTP automation - 4/9/2005 7:31:30 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Replace:

objShell.run "%windir%\system32\ftp.exe -s:" & strControl & strHost

with:

objShell.run "%windir%\system32\ftp.exe -s:" & strControl & " " & strHost

For objShell.run "%windir%\system32\findstr.exe /r sdat[0-9] files.txt >" & strSdatName, could you echo everything without objShell.run and paste it here ?

Also, what happens if you replace the above line with:

objShell.run "cmd /c %windir%\system32\findstr.exe /r sdat[0-9] files.txt >" & strSdatName

(in reply to Zifter)
 
 
Post #: 26
 
 Re: Error handling FTP automation - 4/9/2005 7:56:48 PM   
  pebkacid10t

 

Posts: 2
Score: 0
Joined: 4/9/2005
From:
Status: offline
Thanks Token! You were correct on both suggestions. After a couple other minor additions, the ftp transfer is now successful. For anyone who may be interested in the future, the working script is:

Option Explicit

Dim objFso
Dim objShell
Dim strInstructions
Dim strHost
Dim strInstructions2
Dim strInstructions3
Dim strSdatName
Dim strControl

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")

strInstructions = "C:\getdir.txt"
strHost = "ftp.mcafee.com"
strInstructions2 = "C:\ftppart1.txt"
strInstructions3 = "C:\ftppart2.txt"
strSdatName = "C:\sdatname.txt"
strControl = "C:\control.txt"

With objFso
With .CreateTextFile(strInstructions, True)
.WriteLine "open " & strHost
.WriteLine "cd pub/antivirus/superdat/intel/"
.WriteLine "ls . files.txt"
.WriteLine "close"
.WriteLine "quit"
.Close
End With

objShell.run "%windir%\system32\ftp.exe -A -s:" & strInstructions, 1, True

With .CreateTextFile(strInstructions2, True)
.WriteLine "binary"
.WriteLine "prompt n"
.WriteLine "cd pub/antivirus/superdat/intel/"
.WriteLine "get"
.Close
End With

objShell.run "cmd /c %windir%\system32\findstr.exe /r sdat[0-9] files.txt >" & strSdatName

With .CreateTextFile(strInstructions3, True)
.WriteLine "close"
.WriteLine "quit"
.Close
End With

objShell.run "C:\WINDOWS\system32\command.com /c copy ftppart1.txt+sdatname.txt+sdatname.txt+ftppart2.txt" & strControl
objShell.run "%windir%\system32\ftp.exe -v -i -A -s:" & strControl & " " & strHost

End With

Set objShell = Nothing
Set objFso = Nothing

(in reply to Zifter)
 
 
Post #: 27
 
 Re: Error handling FTP automation - 4/10/2005 8:03:57 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
No problem, glad I could help.

(in reply to Zifter)
 
 
Post #: 28
 
 
Page:  <<   < prev  1 [2]
 
  

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 >> Re: Error handling FTP automation Page: <<   < prev  1 [2]
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