0

Please note: I need to insert some spaces in URLs, because of the restrictions of StackOverflow.

I have a FreeBSD server. I need to backup my previously tar.gz databases on a WebDav cloud storage as Yandex Disk or Box.com or 4Shared.

Everything works fine with Putty, command line after command line. I am be able to upload my file on Yandex Disk:

%cadaver  
dav:!> open https://webdav.yandex.com  
Authentication required for Yandex.Disk on server `webdav.yandex.com':
Username: MyUserName
Password:
dav:/> put MyFile.tar.gz
Uploading MyFile.tar.gz to `/MyFile.tar.gz':  
Progress: [=============================>] 100.0% of 1229518 bytes succeeded.
dav:/> exit  
Connection to ` webdav . yandex . com' closed.  
%

However, my bash script fails to upload my file.

Here is my bash script "criptdav.sh":

#!/bin/sh

/usr/local/bin/cadaver < datadav

Here is my "datadav" file:

open https:// webdav . yandex . com  
MyUserName  
MyPassword  
put MyFile.tar.gz  
exit

Here is Putty screenshot of my bash script:

%sh scriptdav.sh  
dav:!> open https://webdav.yandex.com  
Authentication required for Yandex.Disk on server `webdav.yandex.com': 
Username: MyUserName
dav:/> 
Connection to `webdav.yandex.com' closed.  
%

Nota Bene:

I tried with Yandex, Box, 4Shared. Same result. Script fails to upload my file.

QUESTION:

What's wrong with my bash script?

jww
  • 97,681
  • 90
  • 411
  • 885
user9213279
  • 1
  • 1
  • 1
  • Thank you to S K who edited my message, however, my "Putty screenshots" are broken now, so nobody can understand them now. – user9213279 Feb 21 '16 at 01:25
  • One nitpick: A script starting with `#!/bin/sh`, or meant to be run with `sh yourscript` instead of `bash yourscript`, is not a bash script but a POSIX sh script. They're two different languages. – Charles Duffy Feb 21 '16 at 02:59
  • Anyhow -- haven't looked into cadaver specifically, but in general well-written software (from a security-best-practices perspective) won't accept passwords from stdin, but reads them from the TTY. – Charles Duffy Feb 21 '16 at 03:01
  • 1
    ...if you want a WebDAV client built for behaving well when scripted, I'd consider either `curl` (yes, it can be used for the purpose), or `lftp` (yes, despite having "FTP" in the name, it supports WebDAV). – Charles Duffy Feb 21 '16 at 03:02
  • 1
    See http://stackoverflow.com/questions/1205101/command-line-utility-for-webdav-upload – Charles Duffy Feb 21 '16 at 03:03
  • A full day of trying. Nothing works. – user9213279 Feb 21 '16 at 13:50
  • Speaking as someone who's done it successfully before -- with a medical records system using CaDAVer for file storage a decade ago -- it ain't that hard, but "nothing works" isn't enough to go on to debug. That said, if you were assuming that, say, passwords-on-stdin would work with every single piece of software you tried, it's entirely believable that every single one (or at least whatever subset was well-written re: security best practices) would fail. – Charles Duffy Feb 21 '16 at 14:56
  • I am sorry Charles, I am a big dummy. I work for a week on this script. I cannot succeed to upload my backups through WebDav, Curl, or SFTP. This is why I come at StackOverflow to get help. However, the sterile speeches of experts do not solve problems. Only concrete examples that work are able to solve problems. So, if you have a working bash script, please, share it with us. I thank you. – user9213279 Feb 22 '16 at 07:20
  • If you have a working reproducer for the situation -- for which the uses given in the linked question fail -- please, share it with me. I already linked you to a ticket full of examples that worked for *someone*. If they don't work for you, presumably you've got something a little different in your environment -- but without reproducer code for the server and authentication config, we can't repro that problem, so we can't tell *why* something that worked for someone else won't work for you. – Charles Duffy Feb 22 '16 at 16:44

1 Answers1

4

cadaver will take commands from a file specified by the -r flag, and it will pull credentials from a file in your home dir called .netrc

Create a .netrc file in your home with this in it

machine webdav.yandex.com
login MyUserName
password MyPassword

and call cadaver with this:

cadaver -r datadav https://webdav.yandex.com
mivk
  • 13,452
  • 5
  • 76
  • 69
Rondo
  • 3,458
  • 28
  • 26