kkkani
asked on
Copy Files From Local Server to Remote Server Using ASP
Hi All,
I need some help to copy files from local server to remote server using ASP.
Iam uploading a file to local server using ASP upload and i want to copy the same file to the remote server.
Can i get any code to copy files from local server to remote server.
Thanks and Regrads
kkkani
I need some help to copy files from local server to remote server using ASP.
Iam uploading a file to local server using ASP upload and i want to copy the same file to the remote server.
Can i get any code to copy files from local server to remote server.
Thanks and Regrads
kkkani
But can I use this to copy from the clients pc to the web server?
I get path not found even when I use server.mappath.
Any suggestions?
I get path not found even when I use server.mappath.
Any suggestions?
Sure you can add additional statements that can create a mapped drive on the fly and then delete it when you are done with it. You will have to have admin privledges to be able to accomplish these with little problem though. So you need a small script that will:
1.) Create a connection to the sevrer.
2.) Copy files to the server.
3.) Terminate connection.
Correct?
1.) Create a connection to the sevrer.
2.) Copy files to the server.
3.) Terminate connection.
Correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
WshNetwork.MapNetworkDrive "x:", "\\YourServer\YourShare"
Set MyFile = fso.GetFile("c:\the file you want to copy.txt")
MyFile.Copy ("x:\YourDestination")
WshNetwork.RemoveNetworkDr ive "x:"
Set fso = CreateObject("Scripting.Fi
WshNetwork.MapNetworkDrive
Set MyFile = fso.GetFile("c:\the file you want to copy.txt")
MyFile.Copy ("x:\YourDestination")
WshNetwork.RemoveNetworkDr
Thanks for the help TooKoolKris however:
When I tried the WScript code you just posted I get:
Microsoft VBScript runtime error '800a01a8'
Object required: 'WScript'
By the way this is a Web application using VBScript, JavaScript, HTML in ASP.
I need the file from the users pc, which I find with <INPUT type=file>, to be copied/uploaded to the web server. With the code below I get
Microsoft VBScript runtime error '800a004c'
Path not found
Dim fso, f
src=str_FilePath ' path on users pc
des=(Server.MapPath("../fi les/")) ' It maps as c:\inetpub\wwwroot\webapp\ files
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set f = fso.CopyFile(src, des, OverWriteFiles)
f.Close
Your help is greatly appreciated.
When I tried the WScript code you just posted I get:
Microsoft VBScript runtime error '800a01a8'
Object required: 'WScript'
By the way this is a Web application using VBScript, JavaScript, HTML in ASP.
I need the file from the users pc, which I find with <INPUT type=file>, to be copied/uploaded to the web server. With the code below I get
Microsoft VBScript runtime error '800a004c'
Path not found
Dim fso, f
src=str_FilePath ' path on users pc
des=(Server.MapPath("../fi
Set fso = CreateObject("Scripting.Fi
Set f = fso.CopyFile(src, des, OverWriteFiles)
f.Close
Your help is greatly appreciated.
Well I can't explain why you're getting errors with that code bacause I've tested it fine on XP and 2000 Pro & Server and it works just fine on all three.
With the code that you are using, have you created a share on the server to where you want these files to be copied? Simply trying to map the drive to any ole file path isn't going to work. You need to create a share to map to.
With the code that you are using, have you created a share on the server to where you want these files to be copied? Simply trying to map the drive to any ole file path isn't going to work. You need to create a share to map to.
@lastockUSDA, Did you go through the old question?. Read through the entire post ....Its fairly informative on the permissions issues involved.
As for the error with the code posted by TooKoolKris, change the code to
'>>Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")<<
Set WshNetwork = Server.CreateObject("WScri pt.Network ")
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
WshNetwork.MapNetworkDrive "x:", "\\YourServer\YourShare"
Set MyFile = fso.GetFile("c:\the file you want to copy.txt")
MyFile.Copy ("x:\YourDestination")
WshNetwork.RemoveNetworkDr ive "x:"
Cheers!!
As for the error with the code posted by TooKoolKris, change the code to
'>>Set WshNetwork = WScript.CreateObject("WScr
Set WshNetwork = Server.CreateObject("WScri
Set fso = CreateObject("Scripting.Fi
WshNetwork.MapNetworkDrive
Set MyFile = fso.GetFile("c:\the file you want to copy.txt")
MyFile.Copy ("x:\YourDestination")
WshNetwork.RemoveNetworkDr
Cheers!!
Set fso = CreateObject("Scripting.Fi
fso.copyfile "source path", "destination path", overwrite
The overwrite argument being true or false, its true by default.
You can also use the plain Copy method as well but you need to get the file first.
Set fso = CreateObject("Scripting.Fi
Set MyFile = fso.GetFile("c:\testfile.t
MyFile.Copy ("c:\windows\desktop\test2