Search code examples
bashcygwin

Bash & CYGWIN: SCP does not see files


I have sh script which copies all files from some folder to some host.

scp -r -i PATH_TO_SSH_KEY SOURCE_FOLDER/* SERVER:TARGET_DIR

When I run this script I get the following result:

Cygwin lists all files in my SOURCE_FOLDER and says that these files were not found! "No such file or directory". That looks odd. I have checked that all files in that folder have -rw-r--r-- permissions. I have tried to set higher permissions, but I cannot keep them because the files are regenerated each time I run this script, so they are always like this.

The questions are:

1) which permissions should have files to be transferred by scp?

2) can I setup a folder in a way that all files inside are always created with some predefined permissions?

3) in case my guess about permissions falls - what else can be a reason of this behaviour?


Solution

  • Seems to work for me, but I work in Linux. Not 100% familiar with cygwin. To answer your permissions questions:

    1) The files should be writable. If they're owned by root, well, change the group or use sudo. I'll explain the next step how I'd handle it.

    2) Yes, you'll want to use umask to achieve this. I wouldn't do remote root user copy or 777 permissions. You'd want to assign a umask for that directory and assign certain groups to it. A 002 umask means that all people part of the group in that directory have read write access. The next two commands then add a group to that directory, and the default group for files. The following is an example of the syntax:

    umask 002 <dir>
    chgrp <group> <dir>
    chmod g+s <dir>    
    

    3) Syntax... but I'm guessing permissions. Check permissions of both target and source server.

    I hope this was helpful!

    umask reference: http://man7.org/linux/man-pages/man2/umask.2.html

    cheers!