Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP Unix files using vbscript 1

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
I have this vbscript that runs on an NT server.
If I need to FTP files from our UNIX DB server to our FTP server, can I incorporate this process in the script?

Can I use fileobjectsystem or any other Windows object to manipulate the files in unix (i.e. filexists())?

Any help will be greatly appreciated.
 
EdRev,

You can use FTP in a script, but you would probably have to use the SENDKEYS script command to emulate an "interactive" session.

fengshui1998
 
If you have VB take a look at the WinInet Control (actually called "Internet Transfer Control").

You can also build a text file of commands for FTP.EXE and initiate it from a script.

These are the most common ways people do this.
 
If you don't want to build a command file for FTP (see the FTP help: FTP -? and look for the -s switch) you can also use WShell.Exec to run FTP.

Using the Exec method gives your script access to stdin and stdout so that you can automate FTP that way.
 
Thanks guys!!

I can run the FTP script in our NT server, but I need to know if this script can FTP the files that resides in the UNIX database server into our FTP server?

This will be my script:

set tool = CrateObject("internet.communication")
ftpdir="ftp.xxxxx"
uploadfile= "/hpuxyy/outgoing/upload.txt"
ftpname= "ftpupload"
username="myname"
password="mypwd"

handle=tool.connectftp(ftpdir,username,password)
ok=tool.putfile(handle,upladfile,ftpname)

Will this script (running on NT server), ftp the files from unix? This script is just part of a bigger script that has to run on te NT (web) server.

 
I don't know what ActiveX control has a progid of "internet.communication" - is this a 3rd party control you found someplace?

The "Internet Transfer Control" (also known as the Inet Control) has a progid of "InetCtls.Inet" and there are some things you need to realize about it.

1st thing is, it downloads into a string or a byte array. So if you want the data stored at the NT end as a file you'll need to write it to disk after you get it.

2nd thing is, it operates asynchronously. This means you'll need to wait until it completes. There is a state property you can check for this.

3rd thing is, for long files you'll need to use "getchunk" method calls because otherwise you'll likely run into trouble.

4th thing is, this is a licensed ActiveX control. This means that a WSH script can only use it on a machine that has a design-time license for the control installed. You get this by installing VB6, Visual Interdev, Office Developer, etc. WSH has no mechanism for making use of a run-time license.

The methods offered by Inet include:

* Cancel
* Execute
* GetChunk
* GetHeader
* OpenURL

It also offers a long list of properties and exposes one event: StateChanged.


So in general all of this means that I typically would choose to script the
Code:
ftp.exe
command-line program via the WSH Run or Exec methods. This is least-hassle, most-reliable.

If you found a 3rd-party control that makes FTPing easy, that's great. But I am not familiar with a control like the one you described in your last post.
 
Actually, I got this script fom Tobias Weltner's book Windows Scripting Secret.

About the licensed ActiveX control you mentioned, InetCtls.Inet, I need to install VB6 on our NT server in order to use it? Are there any alternatives?

You also mentioned about scripting the ftp.exe command line program via WSH Run or exec method. I thought that is what I was doing with the sample script. Is it possible for you to provide me with a sample code using this method.

I am also not sure if I can run the vbs script on the NT server when the files that I will FTP are in the UNIX database server




 
Well here is a very basic example:

trans.vbs
Code:
01 Option Explicit
02 Dim WshShell
03
04 Set WshShell = CreateObject("WScript.Shell")
05 WshShell.Run "cmd /C ftp -s:trans.txt >trans.log", 0, True
06 Set WshShell = Nothing
07 MsgBox "Complete", vbOkOnly Or vbInformation, "trans.vbs"
trans.txt
Code:
01 open s123.myoutfit.com
02 bigdog
03 9wolfbane9
04 dir
05 bye
This just fetches the default directory listing, whicih ends up over in the file trans.log.

In your case you'd substitute a get (or several) there at line 04.

User bigdog password 9wolfbane9 is an account over at the FTP server s123.myoutfit.com and I can't see why this couldn't be a *nix machine. You may need to include a cd command or even one or more delete commands in your command (-s:xxx) file - all depends on what you want to accomplish.

No reason why your WSH script couldn't build the file on the fly before running FTP either, especially if the file names to transfer change each run or something. If you need to protect the password build the command file on the fly and remove it after FTP completes.

Note that in line 05 of the script, cmd is for use on NT operating systems. For a Win9x machine substitute command.

I assume that book came with a CD? If not, there are alternative scriptable components out there. A Google search for "free ftp ActiveX" found me:


In most cases just running the regular command-line FTP client as shown above will work fine though. Check out the commands in the Windows FTP client first. Just open a command window, type FTP to start it up, type HELP for a command listing or HELP command for a bit more detail. You can also look at:


There is a nice summary there.

You may need to ensure/prevent binary (image) transfers for example. Binary transfer of a *nix text file to Windows results in a mess unless you know that's what you want. It can't hurt to use the ascii (set text mode) command prior to gets of text files. In the same way something like a JPEG image would be scrambled into a mess if you do a text transfer. Use the binary command to force an exact-image (or binary) transfer.

One way or another this ought to get you on your way. To go further I'd need to send you a bill. ;-) Good luck.
 
Thanks as always.

Just one last question though, does the trans.txt a code file that resides outside of the vbs script.

Sorry if I sound like a newbie, that's because I am.
 
Yep, the command file for FTP is a seperate file. Not code, just the same commands you would type in manually to log on with FTP and tell it what to do, then exit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top