Questions

sftp put command

Tags:
+
0 Votes
Locked

sftp put command

mrlayance
I am trying to get the put command with sftp to upload a whole folder/directory with files within.

Does anyone know how to achieve this?
  • +
    0 Votes
    rmerchberger

    sftp can up/download multiple files (and you can use wildcards) with mput / mget, but I don't think it recreates directory structure.

    Most sftp servers will also speak scp (Secure Copy - still uses the SSH daemon) and if you issue this command:

    scp -r localdir remoteuser@remotehost:/remotedir

    { and if your remote server uses a different port - some are setup for 1922 or 10022 for example, you'll have to add the -P [port] flag before the -r } that should do what you need.

    If your server doesn't support scp and the filenames of the files don't change much either, you might be able to create a batch file of all the commands necessary to recreate the directory structure and use the -b flag for sftp. From the man page:

    -b batchfile
    Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction with non-interactive authentication. A batchfile of '-' may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a '-' character (for example, -rm /tmp/blah*).

    Hope this helps,
    "Merch"

    +
    0 Votes
    oldbaritone

    check mput/mget command.

    +
    0 Votes
    oldbaritone

    check mput/mget command.

  • +
    0 Votes
    rmerchberger

    sftp can up/download multiple files (and you can use wildcards) with mput / mget, but I don't think it recreates directory structure.

    Most sftp servers will also speak scp (Secure Copy - still uses the SSH daemon) and if you issue this command:

    scp -r localdir remoteuser@remotehost:/remotedir

    { and if your remote server uses a different port - some are setup for 1922 or 10022 for example, you'll have to add the -P [port] flag before the -r } that should do what you need.

    If your server doesn't support scp and the filenames of the files don't change much either, you might be able to create a batch file of all the commands necessary to recreate the directory structure and use the -b flag for sftp. From the man page:

    -b batchfile
    Batch mode reads a series of commands from an input batchfile instead of stdin. Since it lacks user interaction it should be used in conjunction with non-interactive authentication. A batchfile of '-' may be used to indicate standard input. sftp will abort if any of the following commands fail: get, put, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod, chown, chgrp, lpwd and lmkdir. Termination on error can be suppressed on a command by command basis by prefixing the command with a '-' character (for example, -rm /tmp/blah*).

    Hope this helps,
    "Merch"

    +
    0 Votes
    oldbaritone

    check mput/mget command.

    +
    0 Votes
    oldbaritone

    check mput/mget command.