1748185 Members
4309 Online
108759 Solutions
New Discussion юеВ

sftp error handling

 
SOLVED
Go to solution
Bill Davison
Occasional Contributor

sftp error handling

Hi,

OS: HP-UX 11.11
HP-UX_Secure_Shell-A.03.81.002

We have batch jobs that were using regular FTP. Since return code=0 is apparently unreliable, we were running ftp in verbose mode and checking for code 226 (Transfer Complete).

QUESTION: Now that we're converting to sftp, what's the *right* way to check for success/failure in batch jobs? Checking for 226 doesn't seem to work with sftp (at least not with the ssh version we're using). Interestingly, Sun's man page says return code=0 means success. But HP's man page is silent on this topic.

If we can't come up with anything better we may go with cksum on the source and target machines.

Thanks in advance
Bill
3 REPLIES 3
Bill Hassell
Honored Contributor

Re: sftp error handling

Like any multi-command process, the return code will always be quite simple: 0=the host was found, and non-zero=host not found. The problem is how can a single number reflect the results of several commands like put or get or cd or lcd, any one of which may fail but others succeed. You'll need to parse each command line's response as to validity. Since ftp does not have any scripting commands to do this, you'll have to examine the entire stdout+stderr output.


Bill Hassell, sysadmin
Colin Topliss
Esteemed Contributor
Solution

Re: sftp error handling

Hi,

This may seem like a silly question, but have you thought of using scp as opposed to sftp?

I used to hit all sorts of problems with something very similar to this (in the early days I ended up using Perl and Net::FTP to start with - I'd have gone on to use Net:SSH had I been able to get it to compile under HP-UX). Recently I just switched over to using scp (much less trouble).

Of course this will depend on what you are trying to achieve and what your overall requirements are.

Colin.
Bill Davison
Occasional Contributor

Re: sftp error handling

Thanks for the input Bill and Colin. I like the scp idea and may end up going that route.

I'll leave this topic open a little longer in case anyone else cares to jump in. I'm still frustrated that there's no documentation or best practices for scripting with sftp - makes it kinda worthless, at least for my purposes.

Bill