Discussion:
Interactive FTP VBScript
(too old to reply)
Patrick
2004-01-21 15:49:51 UTC
Permalink
I know I could use FTP from VBScript using something like the following.
However, is there a better way to do this so it's a little more
"interactive" (i.e., allow the script to interpret intelligently the
response from the server after issuing each command before continuing. e.g.
iff cannot open connection to servername, then it might be worth waiting a
while and then retrying instead of sending a username).

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

sFtpCmds = "c:\ftp.inp"

Set fFtpCmds = oFSO.CreateTextFile(sFtpCmds, _
OverwriteIfExist, OpenAsASCII)

' server to open
fFtpCmds.WriteLine "open servername"
' username
fFtpCmds.WriteLine "username"
' password
fFtpCmds.WriteLine "password"
fFtpCmds.WriteLine "GET testfile.txt"
fFtpCmds.WriteLine "quit"

fFtpCmds.Close

sCmd = "ftp -i -s:" & sFtpCmds

oShell.Run sCmd, 0
Torgeir Bakken (MVP)
2004-01-21 22:40:35 UTC
Permalink
Post by Patrick
I know I could use FTP from VBScript using something like the following.
However, is there a better way to do this so it's a little more
"interactive" (i.e., allow the script to interpret intelligently the
response from the server after issuing each command before continuing. e.g.
iff cannot open connection to servername, then it might be worth waiting a
while and then retrying instead of sending a username).
Hi

Take a look at the components below. They wrap WinInet.dll in a object you can
use from a VBScript:


Ian Morrish's FAQ at http://groups.msn.com/WindowsScript/othercomobjects.msnw
- Free FTP COM Object & sample script
and not so free:
- Is there an FTP COM object that I can use with WSH?

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

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


--
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
Patrick
2004-01-22 11:41:16 UTC
Permalink
I like the first artiicle, but how could I reference a DLL and do something
like the following in a VBScript (as opposed to a VB EXE Application)?
Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName
As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Event removing the "ByVal", "As String" etc it's still coming up as a syntax
error as VBScript does not recognise the keywords like Declare.
Post by Torgeir Bakken (MVP)
Take a look at the components below. They wrap WinInet.dll in a object you can
Ian Morrish's FAQ at
http://groups.msn.com/WindowsScript/othercomobjects.msnw
Post by Torgeir Bakken (MVP)
- Free FTP COM Object & sample script
- Is there an FTP COM object that I can use with WSH?
AspFTP (free)
http://www.15seconds.com/issue/981203.htm
AspInet (free)
http://www.serverobjects.com/comp/AspInet.zip
--
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
Torgeir Bakken (MVP)
2004-01-22 12:13:19 UTC
Permalink
Post by Patrick
I like the first artiicle,
This one you mean?

http://groups.msn.com/WindowsScript/othercomobjects.msnw?action=view_list&row=4&viewtype=2&sortstring=
Post by Patrick
but how could I reference a DLL and do something
like the following in a VBScript (as opposed to a VB EXE Application)?
Private Declare Function InternetOpen Lib "wininet.dll" Alias
You can't call API's from a VBScript. 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 = CreateObject("VBInet.CNetUpload","oInet_")


For the other links I gave you, here is what you need to do before it will work
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")


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")

--
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
Patrick
2004-01-24 01:02:03 UTC
Permalink
Very strangely, with "NIBLACK.ASPFTP", I could get it successfully working
on Windows XP Professional SP2 with IE6SP1, but on a Windows 2000 Server
with SP4 and IE6 with SP1, when I call the oFTP.bConnect, having set the FTP
Server, FTP User name and password properties first, the method returns
False (which indicates a failure), the sError property is not populated
however. There are no errors, however, on creating the object.

However, if I manually try a FTP from the command prompt, I could
successfully connect and authenticate.

what is the likely problem and how could I set about tracking down the
problem? Note that the error number property does not mean much to me
either, just a negative number which does not even correspond to any errors
a FTP server can return!
Post by Torgeir Bakken (MVP)
AspFTP (free)
http://www.15seconds.com/issue/981203.htm
regsvr32.exe "<some path>\aspftp.dll"
(if you want to register it unattended, use regsvr32.exe /s ....)
Set oFTP = CreateObject("NIBLACK.ASPFTP")
2)
AspInet (free)
http://www.serverobjects.com/comp/AspInet.zip
regsvr32.exe "<some path>\ASPINET.DLL"
(if you want to register it unattended, use regsvr32.exe /s ....)
Set oFTP = CreateObject("AspInet.FTP")
--
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
Torgeir Bakken (MVP)
2004-01-25 01:57:59 UTC
Permalink
Post by Torgeir Bakken (MVP)
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.
Set oInet = CreateObject("VBInet.CNetUpload","oInet_")
Oops, that needs to be

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
Patrick
2004-03-07 02:27:59 UTC
Permalink
Has anyone used any of the following FTP DLL Wrapper to wininet.dll?

They seem to work OK for small files. It's hard to tell where the problem
lies.

For instance, with the slightly more advance ASPInet.dll, the
FtpConn.FTPPutFile method returns false when I tried to upload a 70MB binary
file on a remote server running the latest version of Bullet Proof FTP
Server. The remote BFTP Server logs it as Transfer aborted.

Is a FTP with ASPInet.dll, or indeed a hand-crafted DLL wrapper to
wininet.dll any less "reliable" than using the FTP command from the command
prompt in Windows 2000?
Post by Torgeir Bakken (MVP)
Post by Patrick
I know I could use FTP from VBScript using something like the following.
However, is there a better way to do this so it's a little more
"interactive" (i.e., allow the script to interpret intelligently the
response from the server after issuing each command before continuing.
e.g.
Post by Torgeir Bakken (MVP)
Post by Patrick
iff cannot open connection to servername, then it might be worth waiting a
while and then retrying instead of sending a username).
Hi
Take a look at the components below. They wrap WinInet.dll in a object you can
Ian Morrish's FAQ at
http://groups.msn.com/WindowsScript/othercomobjects.msnw
Post by Torgeir Bakken (MVP)
- Free FTP COM Object & sample script
- Is there an FTP COM object that I can use with WSH?
AspFTP (free)
http://www.15seconds.com/issue/981203.htm
AspInet (free)
http://www.serverobjects.com/comp/AspInet.zip
--
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...