简体   繁体   English

将文件复制到远程并创建目录和递归复制

[英]Copying files to remote and creating directories and recursive copying

I am using SSH.NET to copy files using an ScpClient .我正在使用 SSH.NET 使用ScpClient复制文件。 This works fine.这工作正常。 However, if I want to copy files to a destination that doesn't exist yet, there doesn't seem to be a way create the destination path.但是,如果我想将文件复制到尚不存在的目标,似乎没有办法创建目标路径。 I am thinking this is so because it's a limitation of SCP itself.我认为这是因为它是 SCP 本身的限制。

Is there a way around this, or do I need to use an SshClient to first mkdir any necessary paths?有没有办法解决这个问题,还是我需要使用SshClient来首先mkdir任何必要的路径?

Also, there doesn't seem to be a way to copy files recursively (-r flag), but rather, I must copy files individually.此外,似乎没有办法递归地复制文件(-r 标志),而是我必须单独复制文件。 Is that the case as well?情况也是这样吗?

Edit: There is ScpClient.Upload() that takes in a source and destination path, so that can be done.编辑:有ScpClient.Upload()接受源和目标路径,因此可以这样做。

The documentation on the SSH.NET github page is pretty limited. SSH.NET github 页面上的文档非常有限。

First, if you have SCP, you most likely have SFTP too.首先,如果您有 SCP,那么您很可能也有 SFTP。 SFTP and SCP both typically come with an SSH server. SFTP 和 SCP 通常都带有 SSH 服务器。 So if you have SFTP too, use that, as SFTP is a complete protocol that supports not only file transfers (unlike SCP) but also all other file operations, like directory creation.因此,如果您也有 SFTP,请使用它,因为 SFTP 是一个完整的协议,不仅支持文件传输(与 SCP 不同),还支持所有其他文件操作,如目录创建。


Alternatively, as you have found out, if you have a shell access (what is also rather common, if you have SCP access), use shell commands for creating the directly (that is mkdir on Linux shells).或者,正如您所发现的,如果您有 shell 访问权限(这也很常见,如果您有 SCP 访问权限),请使用 shell 命令直接创建(即 ZEDC9F0AA5A3D57797BF6474 上的mkdir

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM