Mel Parish
asked on
Copy file from one server to another via asp vbs
Hello, I have a form that uses fso to pull text file names into a form on an ASP page. I'd like the user to click an export button to send the chosen file over to another server. I have an export.vbs script but I don't now how to pass the value from the asp page to the script. Is there a way to do that? Script below. Hardcoded the script runs great. I don't know how to get the value from the form into the script. This is on an inhouse server.
strFilePath = "\\server1\jobs\source.txt " I'd like source.txt to be the value of my form.
Is there a way to do this?
strFilePath = "\\server1\jobs\source.txt
Is there a way to do this?
The script runs from the asp page like this:
<%if request.form("jobno")>"" then%>
<script>
window.open("export.vbs")
</script>
<%end if%>
export.vbs below
Option Explicit
Dim objFSO, objFileCopy, objGuyFile, objFileDelete
Dim strFilePath, strDestination, WinHttpReq
Dim strFileText, strFileText2, strFileText3
dim fso
strFilePath = "\\server1\jobs\source.txt"
strDestination ="\\server2\export\destination"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(strDestination) then
' Delete file if it alread exists in the destination.
fso.DeleteFile strDestination,True
wscript.echo "File deleted from Server 2"
else
wscript.echo "File wasn't deleted."
end if
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.fileexists(strfilePath) then
Set objFileCopy = objFSO.GetFile(strFilePath)
' copy the file to destination
objFileCopy.copy (strDestination)
WSCript.Echo "The new file has been Copied to " & strDestination
Wscript.Quit
else
wscript.echo "This didn't work. New file WAS NOT copied."
Wscript.Quit
end if
' End of Script
ASKER
No luck. No error though, but the file did not get copied. I don't really understand why either. I made sure to response.write my paths to make sure they were correct and they are. Thanks a million for this help, though. On paper and in theory, it should work perfect. I was pretty excited about it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Death, thanks again but no luck. The error message says the target destination can't be found. Just for fun I ran the vbs script by itself and it works fine. Is there not a way to pass a value to that script and run it? Thanks again.
I don't understand: you said you got an error message, but that it ran fine. What worked, what didn't, and what was the exact error message you got?
ASKER
No, my separate vbs script I have in my original post runs fine. It runs fine separately, outside of the asp page. What won't run is if that code is in the asp.
ASKER
Hey DTS, I'm going to do everything I can to make this form work. The destination server is a linux server and very sensitive. If you have any other ideas to get around the target destination error or why a standalone export.vbs script would run when called from the ASP but not inside of it, let me know. Many many thanks for your help.
It could be a permissions issue, but then I'd expect to see some kind of timeout error message. But that's really as much as I can help out with, without being there in person. Sorry, and good luck!
Open in new window