andy2609
4th November 2011, 14:38
Hi

This relates to Baan Vb running on AS400. I need to create the functionality to 'get' a file (flat text for instance) from a remote server (rather than the platform that Baan is currently running on) and 'put' it in a location on the current server. I am developing this as a Baan 4GL script.

Can anyone offer any assistance with this?

I have considered running a shell script for this (although my shell scripting is more than a little rusty nowadays!), but would prefer to be able to do it solely in the 4GL script.

Any help would be appreciated!

mark_h
4th November 2011, 15:29
Have you tried searching this forum? I know this topic has come up before, but the only way I recall it being solved was with a script. I know that is how we solved it and actually we run the scripts outside of baan in a cron job. That was sufficient for us.

andy2609
4th November 2011, 16:21
Hi Mark

Yes, I searched the forum before I posted, but couldn't find anything. I'll have another look around, if there's no obvious method that I've missed. Thanks for responding.
Andy

mark_h
4th November 2011, 17:05
http://www.baanboard.com/baanboard/showthread.php?t=53937& and search on ftp script(see sample by Ralph) and maybe file.mv(I did not try this one).

andy2609
7th November 2011, 15:12
Thanks a lot Mark - this worked a treat! I must admit that I had not come across these commands before. Here is a snapshot of my solution to share:

extern domain tcmcs.str20 remote.system
extern domain tcmcs.str20 remote.user.login
extern domain tcmcs.str20 remote.user.pwd
long ret_val, rv
long remote.connection
string response(500)

function ftp.connect.get.and.put.example()
{
|## Function 'ftp.init' needs to be called before any other FTP function, otherwise others will fail
|#
ret_val = ftp.init()

|## Open a connection to the remote host
|#
if (ret_val = 0) then
ret_val = ftp.connect(strip$(remote.system), remote.connection)
endif
if (ret_val = 0) then
ret_val = ftp.login(strip$(remote.user.login), strip$(remote.user.pwd), remote.connection)
endif
if (ret_val = 0) then
ret_val = ftp.last.response(remote.connection, response)
else
rv = ftp.last.response(remote.connection, response)
message(strip$(response))
endif

|## Change CURRENT directory on the remote server
|#
if (ret_val = 0) then
ret_val = ftp.chdir("/home/user1/received", remote.connection)
rv = ftp.last.response(remote.connection, response)
endif

|## GET a file from the remote server (sourcef) and direct it to a specific
|## location on the current server ('TARGET', 'SOURCE')
|#
if (ret_val = 0) then
|** ftp.get("TARGET ON LOCAL", "SOURCE ON REMOTE", FTP_BINARY, remote.connection)
ret_val = ftp.get("/home/user1/newfile.txt", "sourcef", FTP_BINARY, remote.connection)
rv = ftp.last.response(remote.connection, response)
endif

|## Optionally PUT a file in the CURRENT directory on the remote server from a specific location
|## on the current server ('SOURCE', 'TARGET')
|## Remember that the current directory must be set with 'chdir' (above) and that
|## the source file must exist on the local server
|#
if (ret_val = 0) then
|** ftp.put("SOURCE ON LOCAL", "TARGET ON REMOTE", FTP_BINARY, remote.connection)
ret_val = ftp.put("/home/user1/forsending/filetosend.txt",
"ftpd.from." & strip$(hostname$()) & ".txt", FTP_BINARY, remote.connection)
rv = ftp.last.response(remote.connection, response)
endif

ret_val = ftp.quit(remote.connection)
}

blanchap
8th November 2011, 17:03
Hi,

one thing you could do also is create an script in unix that will do your ftp and just call a shell command in your baan script.

That's what we did and it's working.

PB

andy2609
9th November 2011, 18:36
Yes - thanks for that tip. This is what I initially considered (see earlier in thread) and I imagine a Unix shell script would work in my case, as the platform is AS400. I have developed this as a 4GL solution and it does everything that it's supposed to, but I would be interested to see your solution and consider as an alternative.

Would you possibly be able to share the shell script solution that you developed?

Thanks for your contribution to this thread

blanchap
9th November 2011, 21:41
Nothing really complicated.

i've created a file in unix: get_file

in that file, i do my ftp.

**********************
echo
echo Retrieving data
echo

cd /baan4/traffic/data

ftp -i -n xxx.xxx.xxx.xxx > /baan4/traffic/ftp.log << -EOF
user login password
ascii
mget W*.CSV
bye
EOF
***********************************

the owner of the file as to be bsp

In my Baan script, i call my shell commande.

choice.cont.process:
before.choice:
ret = shell("/wri/get_file", 0)

After that i read and process the data found in the cvs file.

Regards.

PB

andy2609
10th November 2011, 19:44
Thanks again for that.

BaanInOhio
18th November 2011, 16:16
You can also use the FTP functionality of 'CURL' to perform single line FTP actions that you can build on the fly in the 4gl script. Google "CURL" to see how this slick utility can be used for flexible FTP and to get files from URLs in UNIX.

andy2609
21st November 2011, 10:22
Thanks for your contribution - I'll try this out!