FTP Question #2

Hey guys,
I got a few questions about using FTP in a script in QNX4.

  1. How do you get a list of files to download?
    I’m guessing the answer will be

Dir PATH fileouput
if that the case
How do you open the output file to get the name of each file found?

I’m trying to write an application on a client machine that will be looking for update on a server machine. I’m planning to use an archives file with a tar extension and the the filename will be created with the following

Filename : MachineName-SoftwareVersion.tar

Client will check for update once week and every reboot.
I will be checking for the Software version to prevent multiple install

FSS-105.tar

MachineName=$(filename%-)
SoftwareVersion=$(filename#-
)
SoftwareVersion=$(SoftwareVersion#.*)

Result
MachineName= FSS
SofwareVersion = 105

If a new update is found then I will download the file and install it.

There is a possibility that the directory could have multiple file and that why i have to check every file.

FTP is the only solution that is available for this application. Server can’t notify client for update and I can’t run an application on the server.

Anyone know if FTP is available with TCPIP toolkit?

Johnny,

ftp is available with the standard QNX install.

If you do the following:

Open a file called myFTPScript and type

ls *.tar myUpdateFiles
quit

Then in your C program you can do the following:

system(“ftp -i ftp://username:password@server < myFTPScript”);

This will automatically log in with the username and password on server and download a listing of all files that end in .tar and place them in a file on your local machine called myUpdateFiles. Note you fill in username, password and server with the username, password and IP/DNS name of the server.

Then you can parse myUpdateFiles as you described looking for a newer update. If you find it, you can then download it using another similar system call and install.

This can probably be made more elegant but it does what you need which is getting a file listing on the server of the tar files available.

Tim

Tim,
I’m experiencing on a long delay while using FTP when the server is down.

Any work around for that?

When the system is booting i’m lauching the FTP script. If the server is up then everything is fine but if down. My application will start only after the timeout expired which is way too long. Also how do handle error related to user/password?

I have decide not use the application to check for update. So how do you parse the file list in a script?

Also the archives cksum will be part of the archive filename
MachineName-SoftwareVersion-cksum.tar

How do you cmp the result of cksum with a variable?
Right know i’m using something like

cksum file >> cktarget
cmp -s cksource cktarget
result=$?

if test $result -gt 0
then
#bad
else
#good
fi

Anyway to get the cksum result into a variable? and compare 2 variable instead of file?

Tim I tried to use an application to launch FTp but i’m getting an error

ftp -i ftp://user:passwd@192.168.10.15 > MyFtpScript
Error >Host name lookup failure
If I i’m doing it manually then the connection works fine.

Have a look at the poco library (google it up), it contains a FTP class that will let you do pretty much what you want to do, you should be able to shorten the timeout if the ftp server isn’t there.

Johnny,

I’m going to assume the line

ftp -i ftp://user:passwd@192.168.10.15 > MyFtpScript

is a typo and you meant

ftp -i ftp://user:passwd@192.168.10.15 < MyFtpScript

Not sure why it’s not working from an application. There’s no reason for it not to unless you did indeed mix up the < > signs.

The long delay your experiencing when the server is not there is a function of the TCP/IP stack. I’m not sure if you can change the default timeout. I took a quick look in the doc’s and didn’t see it but there should be a way to lower it.

As for the scripting question, yes, there is a way to do what you want. Maybe someone can chime in with the answer to that. I’d need to look it up in the doc’s (I think it’s under ksh) as it’s not in the top of my head.

The alternative is to use the code base Mario mentions. I’ve never used it myself.

Tim