Search code examples
linuxcommand-lineterminalftpsftp

In "sftp" how to upload all files, but not (sub)folders


In an sftp session, is there a way for me to put the contents of a folder, but only files (not subfolders)? Here's an example.

Folder
    main.py
    config.py
    requirements.txt
    __pycache__ (a folder)

Above is a sample of the local directory. From the folder that encloses Folder, I'd SFTP to the target server. How do I put only main.py, config.py, and requirements.txt (they're files not folders)? . I don't want to put __pycache__ as it's a folder.

If I put -r Folder it will copy Folder and all its contents, including __pycache__. If I put -r Folder/*, it will put all the contents of Folder, without Folder itself, including __pycache__. This is close to what I want. A variant of put -r Folder/* that only copies file contents, not subfolders. So it would skip the __pycache__ folder when copying contents.

Thanks!


Solution

  • Just remove the -r if you do not want to recurse into the subdirectories:

    put Folder/*