Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2004, 10:55 AM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default FTP a file with the Windows Shell

Hello, and many thanks for giving this a little thought...

I'm wondering if there's a way to create an object that acts as the ftp.exe that you can run in the windows shell...

I don't need anything complicated, this is the 'pseudo code' that I have in mind:

Dim strFtpSite, strFtpUser, strFtpPass
Dim str_Path_To_File_To_Ftp

strFtpSite = "ftp.whatever.tz"
strFtpUser = "username"
strFtpPass = "password"

Set objFtp (Whatever the object is that would let me do this)

then use the object to open the FTP connection, supply the username and password, and put the strPath_To_The_File_To_Ftp on the server, and then close the connection.

I don't need logging, or anything else, I just want to put a file on a server as simply as possible... any ideas?

Thanks!!!

Darin


 
Old July 7th, 2004, 06:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Darin,

You can use Windows Scripting Host object and run FTP using that with all parameters that you need to pass through as variables to achieve that.

You can create a batchfile called testftp.bat containing the following. This enables ftp run under interactive mode and takes a file as input that contains commands in it, which gets executed once ftp session is created.
Code:
ftp -i -s:cmds.txt REMOTE_SERVER_IP
Where CMDS.TXT is a textfile contains ftp commands for transfering the files as follows. This can be generated from your ASP/VBscript to have different files used for transfer.

anonymous --username
anonymous --password
hash
binary
mput YOURFILE.ZIP
bye

Your VBScript can be as follows
Code:
set Wshshell= WScript.createobject("wscript.shell")
strCmd = "YOURPATH\testftp.bat"
RetCode = Wshshell.run(strCmd, 1, TRUE)
set Wshshell = Nothing
Hope that helps
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 7th, 2004, 09:47 PM
Authorized User
 
Join Date: Dec 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Howdy Vijay,

Thanks for the incredibly fast response...

Your suggestion is just what I'm looking for!

Just to try, I changed it, just a little bit, so that I could run it all within the script here is what I tried, and the error that I got (essentially all I did was take the bat file that you suggested, and make it a string to pass to the shell.run function - but the error I got is likely the reason why you had it as a batch file in the first place...):

Code:
set Wshshell= WScript.createobject("wscript.shell")
strCmd = "ftp -i -s:cmds.txt REMOTE_SERVER_IP"
Call Wshshell.run(strCmd, 1, TRUE)
set Wshshell = Nothing
when I run it, I get this error:

Error Type:
Microsoft VBScript runtime (0x800A0046)
Permission denied
/scripts/util_ftp.asp, line 58 <- The line "Call Wshshell.run..."

Any ideas?

Thank you _SO_ much!

Darin


 
Old July 8th, 2004, 04:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Darin,

I had posted the VBScript code in my previous post, If you got to use that in ASP then replace WSCRIPT with SERVER there.

Code:
set Wshshell = Server.CreateObject("Wscript.Shell")
Regarding the BATCH file and CMDS.txt, I thought you would need to transfer different files at different times, so the code in my previous post deals with generating CMDS.txt just before executing the FTP command, so that the file to be transferred (marked in blue there) is dynamic and gets generated everytime / passes as parameter.

So keeping that in mind I has posted you all that. But you wanted it simple;), with which you can transfer the same file that is in CMDS.txt

Still here you got to use your remote server's name or its IP
Code:
strCmd = "ftp -i -s:cmds.txt REMOTE_SERVER_IP"
It is not an ASP variable though.

Anyways all the best.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Souce Code Not found (WINDOWS SHELL PROGRAMMIN) Hakeem Visual C++ 1 May 2nd, 2011 02:53 PM
ftp file upload yugi9966 ADO.NET 1 August 7th, 2008 09:09 AM
How to change FTP File permissions malay mehta PHP How-To 0 October 29th, 2007 05:18 AM
Shell command under Windows Vista mileski Access VBA 0 April 16th, 2007 10:17 AM
FTP using windows Application(C#.Net) prasannagps C# 0 July 2nd, 2005 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.