Search code examples
sftp

sftp recursive put creates files from subdirectories in the root directory


I have a local directory structure like this on windows

- install_k3s.yaml
- files
  - registries.yaml

When I try to transfer this folder structure to a linux remote using the following sftp command

put -r *

All the files get created in the root directory on the remote so I end up with the following file structure

- install_k3s.yaml
- files
- registries.yaml

Notice that regisgtries.yaml is no longer in the files folder.

Even if if I manually create the files folder on the remote and then run put -r * registries.yaml is not put in the files folder, it still goes into the root.

I am getting around it for now by using scp, but as that is not secure we are being told to move to sftp, but this recursive issue seems like its going to be a problem.

What am I doing wrong?


Solution

  • yes, because you must use the lcd command in SFTP to change the local working directory to the parent directory of the files folder before running the put -r command!

    something like this :

    lcd C:\path\to\parent\directory
    

    and now, again like this:

    put -r files
    

    you can also use the mput command to transfer multiple files and directories while preserving their directory structure, like this:

    mput -r *
    

    good luck!