Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FTP Help needed

40 views
Skip to first unread message

Scott Bryant

unread,
Feb 5, 2004, 10:41:17 PM2/5/04
to
Can someone please tell me where I can find some useful
information on how to retrieve a file via ftp in a
vbscript? I've found countless articles about msinet.ocx,
but not much on how to use it. i'm having to go through a
proxy server to get the file.

McKirahan

unread,
Feb 6, 2004, 9:27:32 AM2/6/04
to
"Scott Bryant" <brya...@gt.rr.com> wrote in message
news:b97101c3ec63$13fb2750$a501...@phx.gbl...

Will this help?

'* This VBS (Visual Basic Script) program:
'* 1) Creates "ftp_get.ftp" to download a file.
'* 2) Deletes "ftp_get.ftp" after the download.

Option Explicit
Call doFTP()

Sub doFTP()
'*
'* Declare Constants
'*
Const cVBS = "ftp_get.vbs"
Const cFTP = "ftp_get.ftp"
Const cFOL = "c:\temp\"
Const cDOM = "127.0.0.0" '= FTP Domain
Const cUSR = "username" '= FTP Username
Const cPWD = "password" '= FTP Password
Const cFIL = "filename.txt" '= FTP Filename
Const cDIR = "folder" '= FTP Folder
Const cWSS = "%comspec% /C " '= FTP Execution
'*
'* Declare FTP
'*
Dim strFTP
strFTP = cFOL & cFTP
Dim strOTF
strOTF = "open " & cDOM & vbCrLf
strOTF = strOTF & cUSR & vbCrLf
strOTF = strOTF & cPWD & vbCrLf
strOTF = strOTF & "hash" & vbCrLf
strOTF = strOTF & "ascii" & vbCrLf
strOTF = strOTF & "cd " & cDIR & vbCrLf
strOTF = strOTF & "get " & cFIL & " " & cFOL & cFIL & vbCrLf
strOTF = strOTF & "close" & vbCrLf
strOTF = strOTF & "bye" & vbCrLf
MsgBox strFTP & vbCrLf & strOTF,vbInformation,cVBS
'*
'* Delete ".ftp"
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*
If objFSO.FileExists(strFTP) Then objFSO.DeleteFile(strFTP)
If objFSO.FileExists(strFTP) Then
MsgBox "'" & strFTP & "' still exists!",vbExclamation,cVBS
Exit Sub
End If
'*
'* Create ".ftp"
'*
Dim objOTF
Set objOTF = objFSO.OpenTextFile(strFTP,2,true)
objOTF.WriteLine(strOTF)
objOTF.Close()
Set objOTF = Nothing
'*
'* Transfer
'*
Dim objWSS
Set objWSS = CreateObject("WScript.Shell")
objWSS.Run cWSS & " ftp -i -s:" & strFTP,2,True
Set objWSS = Nothing
'*
If objFSO.FileExists(strFTP) Then objFSO.DeleteFile(strFTP)
If objFSO.FileExists(strFTP) Then
MsgBox "'" & strFTP & "' still exists!!",vbExclamation,cVBS
Exit Sub
End If
'*
Set objFSO = Nothing
End Sub


Torgeir Bakken (MVP)

unread,
Feb 6, 2004, 9:33:41 AM2/6/04
to
Scott Bryant wrote:

Hi

You can run ftp.exe from command line/batch/vbscript, using an input file
with -s:

http://groups.google.com/groups?th=dc0c0f2ec58712ff

http://groups.google.com/groups?th=d4a8746457a4297f


If you want more control, take a look at the components below.
They wrap WinInet.dll in a object you can use from a VBScript:


1)
AspFTP (free)
http://www.15seconds.com/issue/981203.htm

Download 981203.zip and unpack it. Register the dll aspftp.dll:

regsvr32.exe "<some path>\aspftp.dll"
(if you want to register it unattended, use regsvr32.exe /s ....)

you can then connect to the object like this:

Set oFTP = CreateObject("NIBLACK.ASPFTP")

See AspFTP2_Doc.htm in the zip file for documentation and e.g. AspFTP2_Get.asp
and AspFTP2_Put.asp for examples.

An example here as well:
http://groups.google.com/groups?selm=tKWmLfM5DHA.4028%40cpmsftngxa07.phx.gbl


2)
AspInet (free)
http://www.serverobjects.com/comp/AspInet.zip

Download AspInet.zip and unpack it. Register the dll ASPINET.DLL:

regsvr32.exe "<some path>\ASPINET.DLL"
(if you want to register it unattended, use regsvr32.exe /s ....)

you can then connect to the object like this:

Set oFTP = CreateObject("AspInet.FTP")

See InetAsp.doc in the zip file for documentation and InetFtp.asp for examples

An example here as well:
http://groups.google.com/groups?selm=tKWmLfM5DHA.4028%40cpmsftngxa07.phx.gbl


3)
Ian Morrish's FAQ at http://groups.msn.com/WindowsScript/othercomobjects.msnw
- Free FTP COM Object & sample script

To use the example in the link above, you
need to run the exe file vbInet.exe that is inside the zip file vbInet.zip once

(it is a self registering exe file). vbInet.exe is a component that wraps the
API's so you can use it from a vbscript.

After you have run vbInet.exe, you can connect to the object like this:

Set oInet = WScript.CreateObject("VBInet.CNetUpload","oInet_")


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


0 new messages