如何使用命令行通过 PuTTy 将文件从 Windows 机器上传到 Linux 机器?

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

How to upload a file from Windows machine to Linux machine using command lines via PuTTy?

windowslinuxfile-uploadcommand

提问by

I'm running Windows on my laptop at the moment and I want to upload files from my laptop to my uni's general purpose server, which runs both Linux and MacOSX.

我目前在我的笔记本电脑上运行 Windows,我想将文件从我的笔记本电脑上传到我的 uni 通用服务器,该服务器运行 Linux 和 MacOSX。

So, I already opened up a connection to that server using PuTTy. But I failed to trying to upload a file from my laptop to that server using the commands guided in this website: http://news.metaparadigma.de/linux-upload-and-download-via-ssh-terminal-226/. Seems like it only works for Linux to Linux machine. It didn't recognize the Windows path that I entered (i.e. C:\a.txt).

因此,我已经使用 PuTTy 打开了与该服务器的连接。但是我没有尝试使用本网站中指导的命令将文件从我的笔记本电脑上传到该服务器:http: //news.metaparadigma.de/linux-upload-and-download-via-ssh-terminal-226/。似乎它只适用于 Linux 到 Linux 机器。它无法识别我输入的 Windows 路径(即 C:\a.txt)。

How can I do this?

我怎样才能做到这一点?

采纳答案by Devin M

Try using SCP on Windows to transfer files, you can download SCP from Putty's website. Then try running:

尝试在 Windows 上使用 SCP 传输文件,您可以从 Putty 的网站下载 SCP。然后尝试运行:

pscp.exe filename.extension [email protected]:directory/subdirectory

There is a full length guide here.

这里有一个完整的指南

回答by gsjha

Use putty. Put install directory path in environment values (PATH), and restart your PC if required.

使用腻子。将安装目录路径放在环境值 (PATH) 中,并根据需要重新启动 PC。

Open cmd (command prompt) and type

打开cmd(命令提示符)并输入

C:/> pscp "C:\Users/gsjha/Desktop/example.txt" user@host:/home/

It'll be copied to the system.

它会被复制到系统中。

回答by Gaurav Komawar

Better and quicker approach without any software to download.

更好更快的方法,无需下载任何软件。

  • Open command prompt and follow steps mentioned below
  • cd path/from/where/file/istobe/copied
  • ftp (serverip or name)
  • It will ask for Server(AIX) User: (username)
  • It will ask for password : (password)
  • cd path/where/file/istobe/copied
  • pwd (to check current path)
  • mput (directory name which is to be copied)
  • 打开命令提示符并按照下面提到的步骤操作
  • cd path/from/where/file/istobe/copyed
  • ftp(服务器 IP 或名称)
  • 它将询问服务器(AIX)用户:(用户名)
  • 它会要求输入密码:(密码)
  • cd path/where/file/istobe/copyed
  • pwd(检查当前路径)
  • mput(要复制的目录名)

This should work.

这应该有效。

回答by Anubioz

Pscp.exe is painfully slow.

Pscp.exe 非常缓慢。

Uploading files using WinSCPis like 10 times faster.

使用WinSCP上传文件快 10 倍。

So, to do that from command line, first you got to add the winscp.comfile to your %PATH%. It's not a top-level domain, but an executable .comfile, which is located in your WinSCP installation directory.

因此,要从命令行执行此操作,首先必须将winscp.com文件添加到 %PATH%。它不是顶级域,而是一个可执行.com文件,位于您的 WinSCP 安装目录中。

Then just issue a simple command and your file will be uploaded much faster putty ever could:

然后只需发出一个简单的命令,您的文件就会以更快的速度上传:putty:

WinSCP.com /command "open sftp://username:[email protected]:22" "put your_large_file.zip /var/www/somedirectory/" "exit"

And make sure your check the synchronize folders feature, which is basically what rsyncdoes, so you won't ever want to use pscp.exe again.

并确保您检查同步文件夹功能,这基本上是什么rsync,所以您将永远不想再次使用 pscp.exe。

WinSCP.com /command "help synchronize"