|
|
Home » ASP » Article
FTP using only pure ASP without using 3rd-party components
|
| Article by: | Ben Meghreblian (10/11/2002) |
|
| Sponsored by: | FindMyHosting - Web Hosting Search |
| Summary: | A real treat for ASP developers - sample code to access the Windows Shell and use ftp commands from within a standard ASP page - no components needed. |
|
| Viewed: 37445 times |
Rating (71 votes): |
|
4.7 out of 5 |
|
|
|
FTP using only pure ASP without using 3rd-party components
by Ben Meghreblian (Visit Ben's site)
Many ASP developers are unaware of the powerful ("WSCRIPT.SHELL") serverobject that is accessible from within a standard ASP script.
In this sample, a combination of the wscript.shell object and the filesystem object is used to create a programmed ftp command.
|
|
View highlighted Comments
User Comments on 'FTP using only pure ASP without using 3rd-party components'
|
|
|
Posted by :
Archive Import (homie) at 17:54 on Monday, January 13, 2003
|
it did work for me, but now I get an error "0" when I the code hits the .run line. weird thing is it works without the output redirect to the temp file. any ideas?
| |
Posted by :
Archive Import (homie) at 17:57 on Monday, January 13, 2003
|
woops, I meant error code of 1, not 0.
| |
Posted by :
Archive Import (A-109) at 08:43 on Monday, January 20, 2003
|
Hi,
I got this error
:Error Type:(0x80040111) ClassFactory cannot supply requested class
Could anyone help me? I don't know what it means.
| |
|
|
Posted by :
Archive Import (Guy) at 13:31 on Tuesday, February 11, 2003
|
Hi,
Is it possible to upload files from the client (running IE5.5) to the server ?
Thank you for your help
| |
Posted by :
Archive Import (Chris) at 11:47 on Tuesday, February 25, 2003
|
Genius..
As long as you follwo the instructions and have your server set up correctly - everything works perfectly - saved me lots of time.
| |
Posted by :
Archive Import (neil) at 06:33 on Wednesday, March 05, 2003
|
anyone know of a asp.net equilavalent??
Neil.
| |
Posted by :
Archive Import (I.Turvey) at 05:07 on Monday, March 17, 2003
|
Re: As long as you follwo the instructions and have your server set up correctly
What do you have to do to the server?
I cannot get this to run...
| |
Posted by :
Archive Import (dave) at 07:26 on Monday, March 17, 2003
|
You will need write permissions in the folder that you are trying to ftp to, other than that, ensure all the variables are set correctly below the line " Edit these variables to match your specifications "
Hope that helps.
| |
Posted by :
Archive Import (bhaskaran) at 08:27 on Monday, March 17, 2003
|
works fine
can i change a ftp user name and password using asp ????
| |
Posted by :
Archive Import (TShrack) at 13:11 on Thursday, April 03, 2003
|
Wow! All I can say is thanks. This script works perfectly for my application.
| |
Posted by :
Archive Import (I.Turvey ) at 07:38 on Wednesday, April 16, 2003
|
What do you change on lcd line?
objTextFile.WriteLine "lcd " & Server.MapPath(".")
my local path is c:\inetpub\wwwroot\dat\
putting this in doesnt seem to work..
| |
Posted by :
Archive Import (Siva) at 12:04 on Wednesday, April 30, 2003
|
Ho do I display ftp directory listing in an ASP page. Can you please help me.
Thanks
| |
Posted by :
Archive Import (Farhad) at 05:34 on Thursday, May 01, 2003
|
Excellent piece of code
Well done Ben Meghreblian :)
| |
Posted by :
Archive Import (Farhad) at 05:08 on Saturday, May 03, 2003
|
How can i display error messages generated (such as file not found etc,)in a customized way using this code.
| |
Posted by :
Archive Import (burger) at 15:12 on Tuesday, May 06, 2003
|
Does the file (to be uploaded) have to exist on the server?
Is there a way to transfer the file from the client to the FTP server directly?
I'm new to this.
Thanks
burg
| |
Posted by :
Archive Import (jini) at 13:44 on Tuesday, May 13, 2003
|
ben,
i can't believe this worked on the first try. so many times i've downloaded code samples, and i usually have to mess with it to make it work.
your code worked right away! also, it's so darn useful -- just what i was trying to do today.
| |
Posted by :
Archive Import (guy broeckx) at 11:41 on Wednesday, May 14, 2003
|
Works fine but I want to FTP some images and want to rename the files first. Is it possible ?
| |
Posted by :
Archive Import (mike) at 12:44 on Thursday, May 22, 2003
|
i got it working, but can i rename the file remotely?
Thanks,
| |
Posted by :
Archive Import (kelly) at 12:52 on Friday, May 23, 2003
|
Ben,
I used the code and it worked perfectly! However, now my username and password for the ftp sever has changed and it keeps looking for the old password. Is there a way I can correct this?
Thanks,
Kelly
| |
Posted by :
Archive Import (Johnny Yee) at 22:39 on Sunday, May 25, 2003
|
What do you change on lcd line?
objTextFile.WriteLine "lcd " & Server.MapPath(".")
The local path seems to be the server.
my local path is c:\inetpub\wwwroot
What should I do if I want to upload file from my local machine to server.
Thank You
| |
Posted by :
Archive Import (Enric Masdeu) at 09:32 on Monday, May 26, 2003
|
Does the file (to be uploaded) have to exist on the server?
Is there a way to transfer the file from the client to the FTP server directly?
Thanks
| |
Posted by :
Archive Import (Primal) at 01:01 on Wednesday, May 28, 2003
|
This code works great - can't believe it worked first try - well done!!!
One quick question though - is it possible to create a folder on the ftp sever using this code??
| |
Posted by :
Archive Import (Rick) at 22:52 on Thursday, June 05, 2003
|
Pardon my ignorance, but it appears that this code only works if the machine that contains the file to be ftp'd is running a server of some sort that exposes it to the internet. In other words, I can't ftp files from the client, correct?
| |
Posted by :
Archive Import (Chean) at 03:50 on Friday, June 06, 2003
|
This code doesn't seem to work for me.
When it execute the username it comes up with invalid command.
All the code after that, doesn't seem to work. It all return invalid command and Not Connected.
how can i fix this.
| |
|
|
Posted by :
Archive Import (Kathryn Rayner) at 18:22 on Wednesday, August 20, 2003
|
Thanks bunches! I was able to modify the code to retrieve files from an FTP site using mget followed by delete instead of mput.
| |
Posted by :
Archive Import (bret) at 14:45 on Friday, September 12, 2003
|
I've used this technique for ftp in the past, but I've never tried it in ASP until reading your article. Good job, it worked great!
| |
Posted by :
jazzym at 06:01 on Wednesday, December 17, 2003
|
I used the code on my local machine running XP Pro with IIS. Worked fine as long as the path to the ftp commands file wasn't in a long named directory.
BUT.. i've uploaded the script to my web space to see if i could get it to work there. It doesn't but it throws out no errors. I've even tried to put in some dodgy file name in the shell run command and it still doesn't error. Is this normal? Could it be a permissions thing that the ISP have stopped people from being able to do this on their server? Surely there should be SOME kind of error. Why would i get none?
I've even tried removing the ON ERROR RESUME NEXT line, still no errors.
Any help greatly appreciated.
Cheers!
| |
Posted by :
Sofyris at 06:20 on Wednesday, January 14, 2004
|
Hello,
This method used to work on a NT server, now it doesn't on 2000 server. In fact, the lcd command is uneffective, without any error or acknowledgment message , and the "get" action puts the file in the Windows/system32 directory instead of directory indicated in the "lcd" command.
Thanks for your help
| |
Posted by :
kalaria1 at 12:37 on Tuesday, February 10, 2004
|
Hi,
I don't know somehow the code doesn't work for me, i changed the servername, username and password, also the file that i m trying to upload is in the same folder as my .asp file wherein I have the code. I would really appreciate if someone can help.
thank you.
| |
Posted by :
JayeshP at 04:23 on Wednesday, February 11, 2004
|
I seem to have the same problem as kalaria1. All is in place but when i run the script, the only thing that happends is it creates a text file. can sombody please help??
<Added>
thanks
| |
Posted by :
JayeshP at 15:35 on Thursday, February 12, 2004
|
| |
Posted by :
chrislee at 03:54 on Tuesday, February 24, 2004
|
I have the same problem as JayehP. All I get when executing the the test.ftp file but seens to stop at the
Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True).
Would appreciate if anyone could help!!!!
| |
Posted by :
imughal at 02:27 on Wednesday, April 28, 2004
|
How to upload multiple files.
To upload file
ftp_files_to_put = "file.txt"
What about multiple file upload. How to assign multiple file, i tried to give like that
ftp_files_to_put = "file1.txt, file2.txt" OR
ftp_files_to_put = "file.txt" , "file2.txt"
But nothing is working.
Kindly tell me how to upload multiple files.
Thanks
| |
Posted by :
Sri at 07:26 on Thursday, June 03, 2004
|
please mention in details what parameters I have to cghange in order to run the script on my Windos XP m/c
| |
Posted by :
kbrady at 16:29 on Thursday, June 17, 2004
|
In February you posted a problem with a script that you were trying to run:
http://www.codetoad.com/asp_ftp.asp
I am also having the same problem whereby it gets to the following line and it errors out:
Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)
Here is the error:
Microsoft VBScript runtime error '800a0046'
Permission denied
/HomePages/uploadPDF/uploadPdf.asp, line 64
I have made sure that I have write permissions on the directory where the files are being FTP'd to as well as write permissions on the Directory where the script is executing as well as where the test.ftp file lives.
Have you had any more additional luck with this?
I have been working on this for 2 days now and still nothing!
| |
Posted by :
chon at 16:49 on Monday, July 12, 2004
|
I'm getting the "Permission denied" error, as well. This appears to be a restriction on calling ftp.exe from the Windows Script Shell object as I can ftp from the server all I want when logged in. Is it possible to allow ftp.exe to be called from WScript.Shell, and if so, where is that permission set? Thanks.
| |
Posted by :
molmon at 16:15 on Wednesday, October 06, 2004
|
Ok, guys. I'm getting the "Permission denied" error, as well. But, this appears to be a restriction running anything from cmd.exe with the Script Shell object as I get this error when I replace the ftp.exe with DIR /on! Are you guys running on XP, SP1 as well? It must be some tightening MS has done with XP. Any comments?
| |
Posted by :
hhead at 15:39 on Friday, January 07, 2005
|
Very....clever way to pipe ftp commands! Thank you
| |
Posted by :
shadie at 15:08 on Thursday, March 17, 2005
|
this is a great piece of code. I've been using it for a couple of months and have had absolutely no troubles! I do have a question though. I'm trying to use it for a different project and would need it to get a file instead of put. I tried the obvious and that was change all the put commands to get but it didn't work. I didn't get any errors, my browser just "spun" with no results. What am I missing?
Thanks in advance.
-shadie
| |
Posted by :
jfpayette at 08:20 on Thursday, May 04, 2006
|
For those who are having a access denied problem, you need to copy 2 files (ftp.exe and cmd.exe) in a directory where IUSER have execute right.
To use mput function, you need to leave a space between each files ex.: "file1.txt file2.txt file3.txt"
Thank for that great code!
| |
Posted by :
benmeg at 13:42 on Friday, June 09, 2006
|
Wow, good to see this is still being used :) Check out some other code of mine at http://benmeg.com/code/ - I'll be adding to it as time goes on...
Thanks,
Ben Meghreblian
| |
Posted by :
kmunj at 06:00 on Thursday, May 10, 2007
|
hi i have change all parameter username ftp server n other but this code dose not work n no error as well, tell me wht to do ??
| |
Posted by :
Andraw Smith at 11:46 on Monday, December 17, 2007
|
Hi, Friends,
I need to get file from our ftp server everyday (I modify the code to: objTextFile.WriteLine "get " & ftp_files_to_put), so I copy your codes to my local machine, and modify variables to match my case, when I run the program, there is no error, but when I check the file using the following code, get the "File not existed" message, do you know what's wrong?
if objFSO.FileExists(strTempFile) then
Response.Write "File existed<br><br>"
Response.Write oFile.Name & "<br>"
Response.Write "oFile.Size = " & oFile.Size/1024 & " MB<br><br>"
else
Response.Write "File not existed<br><br>"
end if
Thanks!
Andraw
| |
Posted by :
drewbkilla at 13:05 on Thursday, February 21, 2008
|
This is an awesome piece of code, however, im getting this following error, im not sure what file is missing becasue the message is fairly plain.
Microsoft VBScript runtime error '800a0035'
File not found
/test/ftp.asp, line 53
strTempFile = "C:\" & oFileSys.GetTempName( )
' Pipe output from cmd.exe to a temporary file (Not :| Steve)
Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)
line 53-->Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)
should I be changing the "C:\" on the above line? Can it be set to a mappath location?
Sorry if it's a dumb question.
Thanks
| |
|
To post comments you need to become a member. If you are already a member, please log in .
| |