Can I copy files to a Network Place from a script or the command line? [closed]
Asked Answered
L

9

12

Is it possible, in Windows XP, to copy files to a Network Place from the command line, a batch file or, even better, a PowerShell script?

What sent me down this road of research was trying to publish files to a WSS 3.0 document library from a user's machine. I can't map a drive to the library in question because the WSS site is only available to authenticate via NTLM on a port other than 80 or 443. I suppose I could alternately use the WSS web services to push the files out, but I'm really curious about the answer to this question now.

Luxembourg answered 13/8, 2008 at 20:2 Comment(1)
also see similar question here: serverfault.com/q/43116/84502Acne
L
1

From what I'm seeing, it seems that it's not possible to directly access/ manipulate a Network Place from the command line, be it in PowerShell or the plain ol' command prompt.

@slipsec (#13899): Thanks for the suggestion, but PowerShell doesn't support the port number in the destination path any more than the net use command does.

So the best thing I can figure to do in my particular situation is bite the bullet and buy something like WebDrive to enable drive mapping via WebDAV on non-standard ports, or do some different configuration (e.g. separate web app with a different IP address and host headers) in SharePoint to expose the site via NTLM on a standard port.

Luxembourg answered 27/8, 2008 at 14:35 Comment(0)
L
19

Using a batch file, you can both log on to the resource and copy the file:

The Batch File would contain the following:

net use \\{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \\{dest-machine}\{destfolder}

e.g.

net use \\Development\myfolder mypassword /user:Administrator
copy newfile.c \\development\myfolder
Lindon answered 18/8, 2008 at 11:6 Comment(0)
T
6

If you are referring to a windows box, just use xcopy. It is pretty standard to have xcopy available.

xcopy src \\dest-machine\shared-library-name\dest
xcopy \\src-machine\shared-library-name\dest src
Thordis answered 19/11, 2011 at 10:5 Comment(0)
S
3

Powershell uses the abstraction of Providers to provide a common interface into datastores. These seem to stick with the common noun "Item", so you can get a complete list with man *item*. If you know another way to copy and otherwise work with data from a store, you might as well use it, but using the cmdlets provides a better "learn-once, use-often" approach. In your case you could:

Copy-Item test.txt -Destination \\dest-machine\share

Copy-item also supports the -Credential parameter if you need it.

Seraphic answered 17/8, 2008 at 20:13 Comment(1)
Copy-Item has a -Credential parameter, but none of the standard providers (namely the filesystem) support it, so it's not really usable.Magnanimous
N
2

"Network Places" doesn't really have an API, it's just a bunch of shortcuts, and the SharePoint share uses a Shell Extension, if I recall correctly.

All of that to say: accessing Sharepoint as a file system from PowerShell also requires an extension, the SharePoint Provider.

Narcosynthesis answered 16/9, 2008 at 2:28 Comment(0)
V
1

you could use the 'net' commands to authenticate and then copy the files.

copy src \\dest-machine\shared-library-name\dest

I'm not really sure exactly how to handle authentication if it's needed.

V answered 13/8, 2008 at 20:8 Comment(0)
L
1

From what I'm seeing, it seems that it's not possible to directly access/ manipulate a Network Place from the command line, be it in PowerShell or the plain ol' command prompt.

@slipsec (#13899): Thanks for the suggestion, but PowerShell doesn't support the port number in the destination path any more than the net use command does.

So the best thing I can figure to do in my particular situation is bite the bullet and buy something like WebDrive to enable drive mapping via WebDAV on non-standard ports, or do some different configuration (e.g. separate web app with a different IP address and host headers) in SharePoint to expose the site via NTLM on a standard port.

Luxembourg answered 27/8, 2008 at 14:35 Comment(0)
T
0

If it's something you need to script, you should consider NAnt.

It's a mainly used for build scripts, but it's very powerful and reasonably easy to get started with.

There's also NAntContrib and the nant ftp task which should help you out.

Trichroism answered 13/8, 2008 at 20:44 Comment(0)
L
0

I could be wrong about this, but I think that neither Nick's robocopy solution or Nathan's copy command solution will work. Robocopy seems to want a mapped drive, which I can't do because it's not running on port 80 or 443, and Windows can't handle a path that includes the port in a UNC-style name:

copy src \\dest-machine:45000\shared-library-name\dest

I didn't see a NAnt task that would handle this situation, either.

I also know there are tools that will allow me to map WebDAV drives. I was more wondering if there was some way to make use of the Network Places that have been set up without using the GUI.

Luxembourg answered 13/8, 2008 at 21:23 Comment(0)
S
-1

Yes you can. I suggest using a tool like robocopy.

Sibbie answered 13/8, 2008 at 20:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.