LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   File transfer: scp from local to windows share (https://www.linuxquestions.org/questions/linux-desktop-74/file-transfer-scp-from-local-to-windows-share-858807/)

danubuntuman 01-26-2011 11:05 AM

File transfer: scp from local to windows share
 
Hi there,

I'm running Ubuntu 10.04 LTS, fresh install, and have been searching far and wide for the answer to this. I think it is probably either something simple, or i'm doing something fundamentally wrong...

1) I have a script which puts all my files into a tar.gz file in a local directory.
2) I have a 'Windows share' mounted using a tool found in 'Places>Connect to server'
This mounts the server to:
Quote:

/home/dan/.gvfs/dan\ on\ servername.ac.uk
3) I wish to copy my backup to the mounted Windows server. So i use the command:
Quote:

scp backup_26-01-2011.tar.gz /home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/
And this completes nicely.

....Start of problem:

4)I wrote a bash script to allow this to run as a cron job:
Quote:

#!/bin/bash
zipname='dan_'`date +%d-%m-%Y`'.tar.gz'
source='/home/dan/temp_backups'
target='/home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/'

scp $source/$zipname $target
The target is correct (browsed there via terminal, and used 'pwd'), but the error i get back is:

Quote:

servername.domain.ac.uk/backup/: No such file or directory
Is there anything particularly wrong with what i'm attempting? My best guess is that the spaces in the mount name are causing a problem, but i've tried using quotation marks in the form of:
Quote:

target='/home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/'
and
Quote:

target='"/home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/"'
Without any change in error message, both when i do and do not include backslashes.

Any help would be much appreciated!

xeleema 01-26-2011 12:35 PM

Greetingz!
Well, for starters, you should probably make a few changes to your script;
Code:

#!/bin/bash
zipname="dan_`date +%d-%m-%Y`.tar.gz"
source="/home/dan/temp_backups"
target="/home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/"
cd ${target}
[ $? -gt 0 ] && \
  {
    print "Cannot find target ${target}! Exiting!"
    return 1
    exit
  } || {
    print "Target found!"

    scp ${source}/${zipname} ${target}
  }


danubuntuman 01-27-2011 05:40 AM

Hi xeleema, thanks for your reply.

I tried putting the code you suggested into my bash script after the part i try to 'scp', and got this back:

Quote:

servername.domain.ac.uk/backup/: No such file or directory
./daily_backup.sh: line 42: cd: /home/dan/.gvfs/dan\: No such file or directory
Warning: unknown mime-type for "Cannot find target /home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/! Exiting!" -- using "application/octet-stream"
Error: no such file "Cannot find target /home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/! Exiting!"
./daily_backup.sh: line 46: return: can only `return' from a function or sourced script

TobiSGD 01-27-2011 05:49 AM

May I ask why you use scp (a tool for copying over the network using SSH) to copy to a local mounted share? Try it with cp instead.

chickenjoy 01-27-2011 05:52 AM

q) if the windows share is mounted locally (via samba); then you can just use "cp" instead.

cp <path_to_file> <windows share mounted directory>

TobiSGD beat me to it.

xeleema 01-27-2011 02:18 PM

Argh, I forgot you have a space in the filename, so ${target} needs to be wrapped in double-qoutes.
Just to be safe, I've wrapped both the "to" and "from" for scp in double-quotes.

Code:

#!/bin/bash
zipname="dan_`date +%d-%m-%Y`.tar.gz"
source="/home/dan/temp_backups"
target="/home/dan/.gvfs/dan\ on\ servername.domain.ac.uk/backup/"
cd ${target}
[ $? -gt 0 ] && \
  {
    print "Cannot find target ${target}! Exiting!"
    return 1
    exit
  } || {
    print "Target found!"
    scp "${source}/${zipname}" "${target}"
  }

Note that I do agree with TobiSGD about using "cp" versus "scp". Since "scp" isn't going to prompt you for authentication, you're not getting any encryption...but I didn't want to ask (just like I didn't want to ask why you have a space in a mountpoint...I mean C'mon! :) )

danubuntuman 01-28-2011 04:53 AM

Thank you for your help, much appreciated! I think the double quotes around the
Quote:

$target
solved my problems!


All times are GMT -5. The time now is 12:11 AM.