Windows复制文件到远程共享目录
When you are writing batch scripts (programs that run in the background without user intervention) you often need to copy a file on to a remote machine. If you are not already connected to the machine you will get this message when you try to initiate the copy:
C:\>copy file.txt \\remote-host\c$
Logon failure: unknown user name or bad password.
0 file(s) copied.
You have tried to access a share that is password protected. You must connect to the share and authenticate yourself. It’s easy to do this viaWindows Exploder->Tools->Map Network Drive… but how do you do it without using the Windows user interface?
As with all Windows commands it is overly complicated and not very simple to remember, so here are a couple of cheat sheets to connect to, view and disconnect from windows shares.
Connect to a share
net use z: /user:domain\user \\host\share password
See the status of a share
net user z:
Disconnect from a share
net use z: /delete
If you don’t specify a drive letter to map the share on to then you can only reference the share by its full name (\\host\share
). You must also disconnect using the full path as well, for example:
net use \\host\share /delete
So to copy a file to a remote machine you can use the following lines:
net use z: /user:domain\user \\host\share password
copy my-file.txt z:\their-file.txt
net use z: /delete
or
net use /user:domain\user \\host\share password
copy my-file.txt \\host\share\their-file.txt
net use \\host\share /delete
depending on whatever floats your boat! Well ok, it’s not that complicated.
推荐阅读
-
桌面远程连接阿里云服务器(windows)后丧失了双向文件复制粘贴功能的解决方案(第一条博客!)
-
java编程根据路径将文件复制到另一个目录下
-
将c:windows.复制到当前目录并显示进度的批处理文件
-
python通过paramiko复制远程文件及文件目录到本地
-
ruby 复制文件到其它机器的共享文件夹 RubyUbuntuSQLF#
-
ruby 复制文件到其它机器的共享文件夹 RubyUbuntuSQLF#
-
需求:将指定目录(包含内容)复制到另一个目录中(利用字节流复制文本文件)
-
JAVA——将一个文件复制到另一个目录下
-
【Java】文件的复制,从目录复制到另一个目录。
-
python复制文件到指定目录的实例