Linux:如何通过sftp将目录中的所有文件发送到远程目录

Ran*_*ash 3 linux sftp

就像标题暗示我有一个本地目录,说:

/home/whoever/files_to_send
Run Code Online (Sandbox Code Playgroud)

我想将该目录中的所有文件发送到远程位置:

my_user@my.server.com:/some/remote/directory
Run Code Online (Sandbox Code Playgroud)

我该怎么做SFTP

附注。我特别需要 SFTP 的答案,我不能使用 SCP 或其他任何东西。

pkh*_*mre 10

您可以将该put命令与-r递归复制选项一起使用。

 put [-Ppr] local-path [remote-path]
         Upload local-path and store it on the remote machine.  If the remote path name is not specified, it is given the same name it has on the local machine.  local-path may contain glob(3) char?
         acters and may match multiple files.  If it does and remote-path is specified, then remote-path must specify a directory.

         If either the -P or -p flag is specified, then full file permissions and access times are copied too.

         If the -r flag is specified then directories will be copied recursively.  Note that sftp does not follow symbolic links when performing recursive transfers.
Run Code Online (Sandbox Code Playgroud)

交互模式

$ sftp my.server.com 
Connected to my.server.com.
sftp> put -r /home/whoever/files_to_send /some/remote/directory
Run Code Online (Sandbox Code Playgroud)

cron 运行的单个命令

$ cat batchfile
put -r /home/whoever/files_to_send /some/remote/directory
$ sftp -b batchfile my.server.com
Run Code Online (Sandbox Code Playgroud)

你真正应该从中学到的是阅读在线手册,sftp(1).