日期:2014-05-16  浏览次数:20773 次

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