Solved

Copy Files From Local Server to Remote Server Using ASP

Posted on 2003-11-17
8
2,561 Views
Last Modified: 2010-08-05
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


0
Comment
Question by:kkkani
  • 4
  • 2
  • 2
8 Comments
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9765803
You can use the CopyFile method to copy files. You need to have a FileSystemObject set first however.

Set fso = CreateObject("Scripting.FileSystemObject")
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.FileSystemObject")
Set MyFile = fso.GetFile("c:\testfile.txt")
MyFile.Copy ("c:\windows\desktop\test2.txt")

 
0
 

Expert Comment

by:lastockUSDA
ID: 9766185
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?
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9767458
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?
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 150 total points
ID: 9769259
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9770828
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

WshNetwork.MapNetworkDrive "x:", "\\YourServer\YourShare"
Set MyFile = fso.GetFile("c:\the file you want to copy.txt")
MyFile.Copy ("x:\YourDestination")
WshNetwork.RemoveNetworkDrive "x:"
0
 

Expert Comment

by:lastockUSDA
ID: 9771279
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("../files/")) ' It maps as c:\inetpub\wwwroot\webapp\files
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CopyFile(src, des, OverWriteFiles)
f.Close

Your help is greatly appreciated.
0
 
LVL 9

Expert Comment

by:TooKoolKris
ID: 9772547
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.
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9776134
@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("WScript.Network")<<
Set WshNetwork = Server.CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")

WshNetwork.MapNetworkDrive "x:", "\\YourServer\YourShare"
Set MyFile = fso.GetFile("c:\the file you want to copy.txt")
MyFile.Copy ("x:\YourDestination")
WshNetwork.RemoveNetworkDrive "x:"

Cheers!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adding items to html ul from on server side. 4 48
CSS Question.. 3 72
syntax error on ASP ? 6 39
Dreamweaver server behavior gone 6 73
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now