• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 851
  • Last Modified:

ftp fails to redirect output??

I have a simple ftp command that ftp's a file from one server to another and redirects its output to a log file. I use a .netrc file with the machine name and put command in it. Problem is, it only writes the log file "sometimes". It's totally intermittant. Any ideas what could case this? Here's the ftp command:
ftp svrName > /myDir/myLogFile

.netrc file:

#svrName start
machine svrName login xxxx password xx macdef init
put /myDir/myFile targetDir/myFile
quit
0
shaner74
Asked:
shaner74
  • 9
  • 5
  • 4
  • +1
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Shaner,

You may have multiple tasks trying to write that output file, which means that they're stepping on each other.

I'd redirect the output to a temporary file, then append it to the LogFile.

You could append it directly to the log file, but that runs the risk of messages from different tasks getting interwoven.  That may be chronologically correct, but not obvious to someone reading the log file.


Good Luck,
Kent
0
 
shaner74Author Commented:
But nothing is being written to the log file at all. It's just remaining unchanged. It's really odd because it's so intermittent.
0
 
omarfaridCommented:
can you give example of successful and failed to log
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
shaner74Author Commented:
The log file is cleared out before ftp'ing anything. Upon a success, the log file will look something like this:
Connected to 172.21.1.103.
220 myTest FTP server (Version 4.1 Mon May 26 21:40:36 CDT 2003) ready.
331 Password required for xxxx.
230 User xxx logged in.
200 Type set to I.
200 PORT command successful.
150 Opening data connection for testFile.
226 Transfer complete.
225280 bytes sent in 0.06821 seconds (3225 Kbytes/s)
local: testFile remote: testFile
221 Goodbye.

On "failure", the log file is just empty.
0
 
omarfaridCommented:
how  do you run the ftp and how do you know that it run when the file is empty ?
0
 
shaner74Author Commented:
The ftp is run from another program. I know it was successful because the file was ftp'd to the server. It's just that for some reason it doesn't write the log file??
0
 
omarfaridCommented:
is it run as a crontab job? can you elaborate more on the other program?
0
 
shaner74Author Commented:
Oh sorry...the other program is run from a database called UniVerse. I use a UniVerse BASIC Execute statement and invoke the shell with a -c so it takes the string as a command. It's run like so:
EXECUTE "sh -c 'ftp ":SVR:" > ":THE.DIR:"/myLogFile"
which translates to:
EXECUTE "sh -c 'ftp svrName > /myDir/myLogFile'"

0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi shaner,

Are the symptoms consistent with how the command is run?  That is, does running the command by hand always generate a logfile but running it from your program not generate a logfile?


Kent
0
 
shaner74Author Commented:
No, running it from the program generates the log file "sometimes".  I'll say, 50% of the time a logfile is generated. This process runs at night so it's been extremely diffcult to troubleshoot.
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Does more than one process write to that logfile?

I'm wondering if the fundamental issue isn't that the output is buffered and that several tasks have their own buffers.


Kent
0
 
shaner74Author Commented:
Hi...no it's just this one process that writes to the log file.
0
 
Kent OlsenData Warehouse Architect / DBACommented:

How do you pipe the commands to the ftp client?

What happens if you wrap the FTP statement in its own script, have the script redirect the output to the logfile, and just call the script from your VB code?


Kent
0
 
shaner74Author Commented:
Kent,
I thought about doing that. Creating a script that does all the work and then just call the script from uv basic. I just can't think of a reason why that method would always succeed vs. the .netrc method??
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Normally, I think of a unix shell as a unix shell.  There's just not a lot of magic there.

It's just an educated guess, but it may be the the UV Basic EXECUTE processor is trying to capture the output of the script that you're trying to redirect.  Odd factors like buffer size, output size, etc. may change slightly between executions of the script and that causes the intermittent difference in what you see.  If EXECUTE is trying to implement the redirect that the shell is also redirecting, really weird things will happen.

You should be able to test this.  Run a modified version of the script a dozen times that you know produces less output than what you normally see logged.  The run it again with results that you know produce more output.  It would be nice if you could pick exact character counts, but it's probably not worth that much trouble.

Kent
0
 
shaner74Author Commented:
hmm? You have a point there Kent. The EXECUTE command in uv has a CAPTURING clause in it that you can use to return any output to the screen. I'm guessing it probably always attempts a capture regardless of that clause being used or not. It could be the execute is grabbing the output before it's redirected, or just plain messing it up somehow. What I'm going to try is to eliminate the ftp redirection, capture the output, then manually write a log file forcing a direct disk write - no buffering. We'll see if that does it.
0
 
omarfaridCommented:
do you say that the file is empty just because you program cold not capture it or it is really empty and if you check it from command line it is empty?
0
 
shaner74Author Commented:
it's really empty. Nothing is redirected to the file by ftp.
0
 
pauloaguiaCommented:
I've found this question while looking for the solution for a similar problem myself.
In my case I was using cron to run the script. I never got output when the script run through cron although it worked perfectly when executed from the command line.


Eventually I found the answer to my problem on my own:

ftp -v ...
The -v flag will make ftp always display the output. Can't really say why I didn't think of that sooner (at least I found a lot of useful things in those 5 hours of research).

Maybe this solves your problem, if you still have it?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now