如何使用 SSH 从我的服务器下载文件(在 Windows 上使用 PuTTY)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22127092/
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 11:25:55  来源:igfitidea点击:

How to download a file from my server using SSH (using PuTTY on Windows)

windowssshdownloadputtyscp

提问by SobieSki

When I try downloading a file from my server onto my computer, it actually downloads the file onto the server.

当我尝试将文件从我的服务器下载到我的计算机上时,它实际上是将文件下载到服务器上。

(Note I am already SSH'd into my server before typing this command. I've watched tutorials on YouTube and people are using their terminal without SSHing into any particular server, however I don't think I can do this with PuTTY on Windows?)

(请注意,在输入此命令之前,我已经通过 SSH 连接到我的服务器。我在 YouTube 上观看了教程,人们正在使用他们的终端而没有通过 SSH 连接到任何特定服务器,但是我认为我无法在 Windows 上使用 PuTTY 执行此操作?)

scp -r -P2222 [email protected]:/home2/kwazy/www/utrecht-connected.nl ~/Desktop/

The problem is that I am specifying the location to download the file as only ~/Desktop/

问题是我指定了下载文件的位置 ~/Desktop/

This creates a folder called Desktopin my server, instead of copying the files onto my local desktop.

这会Desktop在我的服务器中创建一个名为的文件夹,而不是将文件复制到我的本地桌面上。

I'd greatly appreciate any assistance.

我将不胜感激任何帮助。



Update:

更新:

I am able to use this command on Linux.

我可以在 Linux 上使用这个命令。

I have successfully download the folder onto my desktop:

我已成功将该文件夹下载到我的桌​​面上:

I still need insight onto how I can do this on a Windows machine.

我仍然需要深入了解如何在 Windows 机器上执行此操作。

回答by Martin Prikryl

There's no way to initiate a file transfer back to/from local Windows from a SSH session opened in PuTTY window.

无法从 PuTTY 窗口中打开的 SSH 会话启动与本地 Windows 之间的文件传输。

Though PuTTY supports connection-sharing.

虽然 PuTTY 支持连接共享。

While you still need to run a compatible file transfer client (pscpor psftp), no new login is required, it automatically (if enabled) makes use of an existing PuTTY session.

虽然您仍然需要运行兼容的文件传输客户端(pscppsftp),但不需要新的登录,它会自动(如果启用)使用现有的 PuTTY 会话。

To enable the sharing see:
Sharing an SSH connection between PuTTY tools.

要启用共享,请参阅:
在 PuTTY 工具之间共享 SSH 连接



Even without connection-sharing, you can still use the psftpor pscpfrom Windows command line.

即使没有连接共享,您仍然可以从 Windows 命令行使用psftppscp

See How to use PSCP to copy file from Unix machine to Windows machine ...?

请参阅如何使用 PSCP 将文件从 Unix 机器复制到 Windows 机器......?

Note that the scpis OpenSSH program. It's primarily *nix program, but you can run it via Windows Subsystem for Linuxor get a Windows build from Win32-OpenSSH(it is already built-in in the latest versions of Windows 10).

请注意,这scp是 OpenSSH 程序。它主要是 *nix 程序,但您可以通过适用于 Linux 的 Windows 子系统运行它或者从Win32-OpenSSH获取 Windows 构建(它已经内置在最新版本的 Windows 10 中)。



If you really want to download the files to a local desktop, you have to specify a target path as %USERPROFILE%\Desktop(what typically resolves to a path like C:\Users\username\Desktop).

如果您真的想将文件下载到本地桌面,则必须将目标路径指定为%USERPROFILE%\Desktop(通常解析为类似 的路径C:\Users\username\Desktop)。



Alternative way is to use WinSCP, a GUI SFTP/SCP client. While you browse the remote site, you can anytime open SSH terminal to the same site using Open in PuTTYcommand.
See Opening Session in PuTTY.

另一种方法是使用WinSCP,一个 GUI SFTP/SCP 客户端。在浏览远程站点时,您可以随时使用Open in PuTTY命令将 SSH 终端打开到同一站点。
请参阅在 PuTTY 中打开会话

With an additional setup, you can even make PuTTY automatically navigate to the same directory you are browsing with WinSCP.
See Opening PuTTY in the same directory.

通过额外的设置,您甚至可以让 PuTTY 自动导航到您使用 WinSCP 浏览的同一目录。
请参阅在同一目录中打开 PuTTY

(I'm the author of WinSCP)

(我是 WinSCP 的作者)

回答by d3c0y

try this scp -r -P2222 [email protected]:/home2/kwazy/www/utrecht-connected.nl /Desktop

尝试这个 scp -r -P2222 [email protected]:/home2/kwazy/www/utrecht-connected.nl /Desktop

Another easier option if you're going to be pulling files left and right is to just use an SFTP client like WinSCP. Then you're not typing out 100 characters every time you want to pull something, just drag and drop.

如果您要左右拉动文件,另一个更简单的选择是只使用像WinSCP这样的 SFTP 客户端。这样你就不用每次想要拉东西时都输入 100 个字符,只需拖放即可。

Edit: Just noticed /Desktop probably isn't where you're looking to download the file to. Should be something like C:\Users\you\Desktop

编辑:刚刚注意到 /Desktop 可能不是您要将文件下载到的位置。应该是这样的C:\Users\you\Desktop

回答by Ashish

if you install git with git bash, you get SCP available on windows.

如果你用 git bash 安装 git,你就可以在 Windows 上使用 SCP。

回答by jacm365

If your server have a http serviceyou can compress your directory and download the compressed file.

如果您的服务器有http 服务,您可以压缩您的目录并下载压缩文件。

Compress:

压缩:

tar -zcvf archive-name.tar.gz -C directory-name .

Download throught your browser:

通过浏览器下载:

http://the-server-ip/archive-name.tar.gz

http://the-server-ip/archive-name.tar.gz

If you don't have direct access to the server ip, do a ssh tunnel throught putty, and forward the 80 port in some local port, and you can download the file.

如果你没有直接访问服务器ip,通过putty做一个ssh隧道,把80端口转发到某个本地端口,就可以下载文件了。

回答by Luan Souza

You can use the WinSPC program. Its access to any server is pretty easy. The program gives its guide too. I hope it's helpfull.

您可以使用 WinSPC 程序。它对任何服务器的访问都非常容易。该程序也给出了它的指南。我希望它有帮助。