Discussion:
FTP Help needed
(too old to reply)
Scott Bryant
2004-02-06 03:41:17 UTC
Permalink
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
2004-02-06 14:27:32 UTC
Permalink
Post by Scott Bryant
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.
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)
2004-02-06 14:33:41 UTC
Permalink
Post by Scott Bryant
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.
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

Loading...