FTPing Multiple Files with Parameters

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

FTPing Multiple Files with Parameters

Post by Pavan_Yelugula »

Hi All
i am trying to FTP a certain set of files from a file server to my Datastage Server using BASIC Script...

I have a small text file(FTPFile) with the FTP commands which looks as below
----------------
open FTPServerName
username
password
cd FAC
get count.txt
quit
-----------------------------------

My DataStage Basic Commands for calling this file looks like
------------------------------------------------------------------------
cmd = 'ftp -s:c:\FTPFile'
Call DSExecute("NT", cmd , Output, ExitStatus)
If ReturnCode = 1 Then
Call DSLogFatal("CountScript Failed", "JobControl")
End
-----------------------------------------------------------------------

Now i want to pass FTPservername,username and password as parameters

my cmd statement is not allowing any parameters.

Can you please suggest me how i can do this parameters instead of hard coding my values

Thanks
Pavan
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

You need to pass it as parameters to your FTPFile. Like

Code: Select all

FTPFile myServerName userMe passwdMe. 
Your bat file should accept these. Once you can get your FTPFile running from command line. Then you can edit your Cmd as

Code: Select all

cmd = 'ftp -s:c:\FTPFile ':myServerName userMe passwdMe
where myServerName userMe passwdMe will be defined as arguments to your routine.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

i changes the DOS batch file to

[open %1
%2
%3
cd FAC
get count.txt
quit]

and tried executing it from command line as follows...

C:\>dosscript1 servername username password

C:\>open servername
'open' is not recognized as an internal or external command,
operable program or batch file.

C:\>username
'username' is not recognized as an internal or external command,
operable program or batch file.

C:\>password
'password' is not recognized as an internal or external command,
operable program or batch file.]

It is not even recognising and going in to the FTP session to execute any commands....

I changed the batch file as

[ftp
open %1
%2
%3
cd FAC
get count.txt
quit]

With this the script is waiting for my input at the command prompt as

[C:\>dosscript1 servername username password

C:\>ftp
ftp>]

ca you please help me in figure out what i am missing in my DOS batch file

Thanks
Pavan[/code][/b]
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Try this

Code: Select all

ftp << EOF
open %1 
%2 
%3 
cd FAC 
get count.txt 
quit
EOF 
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Nope it doesn't work...

Code: Select all

C:\>dosscript1 servername username password
<< was unexpected at this time.

C:\>ftp << EOF

C:\>
Thanks
Pavan
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Thats unix style. Was hoping it would work on NT. Anyways, check out thiswebsite. It tells you how to build a NT ftp script.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Hi all
The Trick in solving this problem is in making the FTP DOS Script File at run time.
i have written the following DOS script

Code: Select all

set FTPADDRESS=green.rosettamarketing.com
set SITEBACKUPFILE=*.txt

set FTPUSERNAME=%1%
set FTPPASSWORD=%2%
CLS
> script.ftp USER
>>script.ftp ECHO %FTPUSERNAME%
>>script.ftp ECHO %FTPPASSWORD%
>>script.ftp ECHO binary
>>script.ftp ECHO cd FAC
>>script.ftp ECHO prompt
:: Use put instead of get to upload the file
>>script.ftp ECHO mget %SITEBACKUPFILE%
>>script.ftp ECHO bye
FTP -v -s:script.ftp %FTPADDRESS%
Hope this helps people in future reference

Thanks
Pavan
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I am sure it will. Thanks for sharing it with us :P
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
velagapudi_k
Premium Member
Premium Member
Posts: 142
Joined: Mon Jun 27, 2005 5:31 pm
Location: Atlanta GA

Post by velagapudi_k »

My DataStage Basic Commands for calling this file looks like
------------------------------------------------------------------------
cmd = 'ftp -s:c:\FTPFile'
Call DSExecute("NT", cmd , Output, ExitStatus)
If ReturnCode = 1 Then
Call DSLogFatal("CountScript Failed", "JobControl")
End
-----------------------------------------------------------------------

I cant stop wondering how this routine is working. You said if ReturnCode=1 then you are aborting the job and exiting the routine.
But there is no ReturnCode in your routine. It only has ExitStatus. The way the routine is running right now, it will never abort. You should say ExitStatus=1 instead of ReturnCode=1.
Venkat Velagapudi
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Good catch velgapudi_k. Even i missed that the first time. The OP cant get away with it, he will have to fix it or else he will get warning messages saying that the variable was not intialized.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

From "Code Obfuscation 101":

Code: Select all

Equate ReturnCode LITERALLY "ExitStatus"
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Pavan_Yelugula
Premium Member
Premium Member
Posts: 133
Joined: Tue Nov 23, 2004 11:24 pm
Location: India

Post by Pavan_Yelugula »

Thanks for Pointing it out... I am more in to making my DOS Batch File work. i am literally working on the Command Prompt :shock: . Didn't execute the basic Routine as of yet to catch this error.

Thanks for pointing it out and saving me some of my debugging time :D

Thanks
Pavan
Post Reply