Re: Detecting sftp batch upload errors
From: Jim Colten (jim@colten.net)
Date: 02/04/03
- Previous message: Nico Kadel-Garcia: "Re: Detecting sftp batch upload errors"
- In reply to: Mopar Quoplic: "Detecting sftp batch upload errors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: Jim Colten <jim@colten.net> Date: Tue, 04 Feb 2003 04:46:12 GMT
you might want to consider using Expect to spawn an sftp session and
feed it commands while it watches the responnses for the expected vs
unexpected results from each command.
Mopar Quoplic wrote:
>
> I am trying to write a script that will handle automated file
> transfers to and from an sftp server, but am having trouble detecting
> upload errors. What I am trying to do is this:
>
> sftp -oIdentityFile=id_dsa -b batchfile user@server
>
> ...where batch file contains:
>
> put /my/local/file /my/remote/file
> bye
>
> When the upload is successful, everything is fine. If the upload fails
> (because the target directory doesn't exist, or if user doesn't have
> write access to the target directory) sftp does not fail as I would
> expect. The man page says that when using the -b option, sftp will
> "abort" if one of a number of commands fails, including "put." I would
> expect that "abort" means exit with an error status that a script can
> detect, but this doesn't appear to be the case. If I add a line with
> "ls" after the "put" the "ls" is executed regardless of whether the
> "put" was successful indicating that nothing other than the "put"
> aborted, and in either case, sftp does not return an error status.
>
> The same happens when using '-oBatchMode <<' instead of '-b batchfile'
> (not surprisingly):
>
> sftp -oIdentityFile=id_dsa -oBatchMode=yes user@server <<FOO
> > put /my/local/file /my/remote/file
> > bye
> > FOO
>
> Am I missing something obvious? Is there a better way to upload files
> using sftp? In the past I have used scp for scripted file transfers
> (and I saw this suggestion offered elsewhere in this group), but in
> this case the target server only allows sftp access. At the moment,
> the only ways around this that I can see are parsing the output to
> catch error strings, or putting in a "ls" and parsing the directory
> list output to see if the file I uploaded is where I want it to be.
> Neither of those seem like robust solutions. (What if a file with the
> same name was there before - do I then try to parse the file's date
> along with the file name? What if I'm not catching every possible
> error string when I'm parsing the output? etc?)
>
> I'd appreciate any help...
>
> Thanks!
- Next message: Bill Lewis Clark: "Re: PermitRootLogin=yes versus su"
- Previous message: Nico Kadel-Garcia: "Re: Detecting sftp batch upload errors"
- In reply to: Mopar Quoplic: "Detecting sftp batch upload errors"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|