使用 scp 将本地文件从 Windows 复制到远程服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8975798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:08:17  来源:igfitidea点击:

Copying a local file from Windows to a remote server using scp

windowssshcopysudoscp

提问by HelloWorld

So, I'm attempting to simply transfer folder of files from my local computer to a server via ssh and scp. After sudoing I'm using the command as follows:

所以,我试图通过 ssh 和 scp 简单地将文件文件夹从我的本地计算机传输到服务器。sudoing 后,我使用的命令如下:

scp -r C:/desktop/myfolder/deployments/ user@host:/path/to/whereyouwant/thefile

I get the error:

我收到错误:

ssh: C: Name or service not known

ssh: C: 名称或服务未知

I'm guessing its my syntax for c:/desktopetc. Any ideas?

我猜它是我的语法c:/desktop等。有什么想法吗?

BTW I'm using putty + Windows 7.

顺便说一句,我正在使用腻子 + Windows 7。

采纳答案by Serkan Yilmaz

If your drive letter is C, you should be able to use

如果您的驱动器号是 C,您应该可以使用

scp -r \desktop\myfolder\deployments\ user@host:/path/to/whereyouwant/thefile

scp -r \desktop\myfolder\deployments\ user@host:/path/to/whereyouwant/thefile

without drive letter and backslashes instead of forward slashes.

没有驱动器号和反斜杠而不是正斜杠。

You are using putty, so you can use pscp. It is better adapted to Windows.

您正在使用腻子,因此您可以使用pscp。它更适合Windows。

回答by Jason

Drive letters can be used in the target like

驱动器号可以在目标中使用

scp some_file user@host:/c/temp

where cis the drive letter. It's treated like a directory.

c盘符在哪里。它被视为一个目录。

Maybe this works on the source, too.

也许这也适用于源代码。

回答by jedi

On windows you can use a graphic interface of scp using winSCP. A nice free software that implements SFTP protocol.

在 Windows 上,您可以使用winSCP使用 scp 的图形界面。一个很好的免费软件,实现了SFTP 协议

回答by Charles

I see this post is very old, but in my search for an answer to this very question, I was unable to unearth a solution from the vast internet super highway. I, therefore, hope I can contribute and help someone as they too find themselves stumbling for an answer. This simple, natural question does not seem to be documented anywhere.

我看到这个帖子很老了,但是在我寻找这个问题的答案时,我无法从广阔的互联网高速公路中找到解决方案。因此,我希望我可以做出贡献并帮助某人,因为他们也发现自己在寻找答案时跌跌撞撞。这个简单、自然的问题似乎没有记录在任何地方。

On Windows 10 Pro connecting to Windows 10 Pro, both running OpenSSH (Windows version 7.7p1, LibreSSL 2.6.5), I was able to find a solution by trial and error. Though surprisingly simple, it took a while. I found the required syntax to be

在连接到 Windows 10 Pro 的 Windows 10 Pro 上,两者都运行 OpenSSH(Windows 版本 7.7p1,LibreSSL 2.6.5),我能够通过反复试验找到解决方案。虽然出奇的简单,但还是花了一段时间。我发现所需的语法是

BY EXAMPLE INSTEAD OF MORE OBSCURE AND INCOMPLETE TEMPLATES:

举个例子,而不是更模糊和不完整的模板:

Transferring securely from a remote system to your local system:

从远程系统安全传输到本地系统:

scp user@remotehost:\D\mySrcCode\ProjectFooBar\somefile.cpp C:\myRepo\ProjectFooBar

or going the other way around:

或者反过来:

scp C:\myRepo\ProjectFooBar\somefile.cpp user@remotehost:\D\mySrcCode\ProjectFooBar

I also found that if spaces are in the path, the quotations should begin following the remote host name:

我还发现,如果路径中有空格,则引号应从远程主机名开始:

scp user@remotehost:"\D\My Long Folder Name\somefile.cpp" C:\myRepo\SimplerNamerBro

Also, for your particular case, I echo what Cornel says:

另外,对于你的特殊情况,我回应康奈尔所说的:

On Windows, use backslash, at least at conventional command console.

在 Windows 上,至少在常规命令控制台中使用反斜杠。

Kind Regards. RocketCityElectromagnetics

亲切的问候。火箭城电磁学

回答by Aditya

You can also try this:

你也可以试试这个:

scp -r /cygdrive/c/desktop/myfolder/deployments/ user@host:/path/to/whereyouwant/thefile

回答by hehe3301

I have found it easiest to use a graphical interface on windows (I recommend mobaXTermit has ssh, scp, ftp, remote desktop, and many more) but if you are set on command line I would recommend cd'ing into the directory with the source folder then
scp -r yourFolder username@server:/path/to/dir
the -rindicates recursive to be used on directories

我发现在 Windows 上使用图形界面是最简单的(我推荐mobaXTerm,它有 ssh、scp、ftp、远程桌面等等)但是如果你是在命令行上设置的,我会建议使用 cd 进入目录源文件夹,然后
scp -r yourFolder username@server:/path/to/dir
-r表示递归要上的目录使用

回答by Igor Mukhin

Drive letter can be used in the source like

驱动器号可以在源中使用,如

scp /c/path/to/file.txt user@server:/dir1/file.txt