Follow via:
RSS
Email Alert
Question
0 Votes
+ -

sftp put command

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?
17th Jul 2007

Answers (2)

0 Votes
+ -
sftp may not create directory structure, but scp can...
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"
8th Mar 2010
0 Votes
+ -
MPUT
check mput/mget command.
8th Mar 2010
Answer the question
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.