VBS FTP
By nater

'Declaring my stuff
Dim strHost,strUser,strPassword

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'Key Items, host names and etc...

'--------------------------the ftp site
strHost = "hostmame"

'--------------------------username for ftp server
strUser = "username"

'--------------------------password to ftp server
strPassword = "password"



Call Ftp


'********************************************************************************
'* FTP SUB
'********************************************************************************

Sub FTP
Dim objFso
Dim objShell
Dim strInstructions
Dim FTPlog


'Ftp log file logs in directory script ran
ftplog = "ftplog.txt"


Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
'Instruction file for ftp
strInstructions = "C:\Instructions.ftp"


' Creates instruction file modfiy commands as needed
With objFso
With .CreateTextFile(strInstructions, True)
.WriteLine "open " & strHost
.WriteLine "user " & strUser
.WriteLine strPassword
.writeLine "lcd "
.WriteLine "put "
.WriteLine "close"
.WriteLine "quit"
.Close
End With

'* runs ftp Using comspec to get the output of the ftp and put it in a log
objShell.run "%comspec% /c ftp -i -n -s:" & strInstructions & " " & " > " & FTPLog , 1, True

'* Deletes the ftp instruction file
.DeleteFile strInstructions


Const ForReading = 1
'* Checks the ftp log file for errors
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")


Set fFTPResults = oFTPScriptFSO.OpenTextFile(FTPLog, ForReading)
'reads log file into variable
sResults = fFTPResults.Readall
fFTPResults.Close

' checks results for string and will call error handler
If InStr(sResults, "226 Transfer complete.") > 0 Then


ElseIf InStr(sResults, "File not found") > 0 Then
FTPStatus = "Error: File Not Found"
Err.Number = 1

ElseIf InStr(sResults, "cannot log in.") > 0 Then
FTPStatus = "Error: Login Failed."
Err.Number = 1

ElseIf InStr(sResults, "Not connected.") > 0 Then
FTPStatus = "Error: cannot connect."
Err.Number = 1

Else
FTPStatus = "Error: Unknown."

End If

'msgbox FTPStatus

'cleanup
Set oFTPScriptFSO = Nothing
Set objShell = Nothing
Set objFso = Nothing


End Sub

Rating:


0/5 based on 0 votes. The median rating is 0.

Submitted: 11/19/10 (Edited 11/19/10)

Description: Will ftp to a client, create an ftp answer file and execute it.

Tags:

Views: 21 views. Averaging 0 views per day.
In the most recent 30 day period, there've been 0 views.

Previous Article