Mike Caldwell
asked on
Simple VBSCRIPT for inflexible file FTP
I'm hoping that not needing flexibility, building directory names, etc, will make this more simple. Searched all the VBS answers for FTP and they seem overly complex for me, plus the ones I tried tried to create a 'shell' and use Active-X and my system doesn't seem to allow that. I can handle the automation end, just not the FTP part. So assume the following:
1. FTP upload a single PDF file (so, binary).
2. Local path and file name are fixed and known.
3. Log in at the server takes me to the folder I need, so no need to specify.
If I have this I can wrap the loop around it and substitute variables for hard coded names, but can start with hard code that works.
Vista 32Biz.
1. FTP upload a single PDF file (so, binary).
2. Local path and file name are fixed and known.
3. Log in at the server takes me to the folder I need, so no need to specify.
If I have this I can wrap the loop around it and substitute variables for hard coded names, but can start with hard code that works.
Vista 32Biz.
ASKER
So, within my loop I put:
ftp -s:test.scr 11.11.11.11
I see that test.scr is external. Just same in the same directory as the VS script?
Also, this appears to be for a server that allows annonymous guests; how do I provide a password instead?
This is promising; thanks.
ftp -s:test.scr 11.11.11.11
I see that test.scr is external. Just same in the same directory as the VS script?
Also, this appears to be for a server that allows annonymous guests; how do I provide a password instead?
This is promising; thanks.
test.scr is an external text file with ftp commands:
open 11.11.11.11 <- connect to ftp server
user <- perform authentication
guest <- username
guest <- password
put file1 <- file send
quit <-close
then the commandc "ftp -s:test.scr" run the commands in the scr file
open 11.11.11.11 <- connect to ftp server
user <- perform authentication
guest <- username
guest <- password
put file1 <- file send
quit <-close
then the commandc "ftp -s:test.scr" run the commands in the scr file
ASKER
Should any of the terms be in quotes?
ASKER
I'm probably just messing up a detail or two. I have three files in the same folder:
test.pdf
test.scr
test.vbs
I get various error messages on the .VBS file related to "expected statement" and similar. Have tried with and without "end"; the VBS keeps being rejected. Also tried it with the URL in the VBS.
Test.vbs
=======
ftp -n -s:test.scr
end
Test.scr
=======
open 11.11.11.111
user
dad@ipstuff.com
abcd1234
put test.pdf
quit
test.pdf
test.scr
test.vbs
I get various error messages on the .VBS file related to "expected statement" and similar. Have tried with and without "end"; the VBS keeps being rejected. Also tried it with the URL in the VBS.
Test.vbs
=======
ftp -n -s:test.scr
end
Test.scr
=======
open 11.11.11.111
user
dad@ipstuff.com
abcd1234
put test.pdf
quit
ASKER
BTW: the uSoft info shows the URL in the command line of the VBS, not within the .SCR.
Hi, this is how you should have it set up.
Test.vbs
=======
Set objShell = CreateObject("WScript.Shel l")
strCommand = "ftp -s:test.scr"
objShell.Run strCommand, 1, True
Test.scr
=======
open 11.11.11.111
dad@ipstuff.com
abcd1234
put test.pdf
quit
Regards,
Rob.
Test.vbs
=======
Set objShell = CreateObject("WScript.Shel
strCommand = "ftp -s:test.scr"
objShell.Run strCommand, 1, True
Test.scr
=======
open 11.11.11.111
dad@ipstuff.com
abcd1234
put test.pdf
quit
Regards,
Rob.
You have to rename test.vbs in test.cmd
Test.cmd
=======
ftp -n -s:test.scr
=======
Or if you like vbs:
Test.vbs
==============
Dim strCmd
Dim WshShell
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
strCmd = "ftp -n -s:test.scr"
ReturnCode = WshShell.Run(strCmd, 1, True)
Set WshShell = Nothing
==============
Test.cmd
=======
ftp -n -s:test.scr
=======
Or if you like vbs:
Test.vbs
==============
Dim strCmd
Dim WshShell
Set WshShell = WScript.CreateObject("WScr
strCmd = "ftp -n -s:test.scr"
ReturnCode = WshShell.Run(strCmd, 1, True)
Set WshShell = Nothing
==============
ASKER
Getting close. The .CMD extension poit ws correct. Looking at the trace in a CMD window all looks well, except the file isn't at the server. The last two lines are:
fpt>put test.pdf
200 PORT command successful
It seems to hang up on that last line.
fpt>put test.pdf
200 PORT command successful
It seems to hang up on that last line.
ASKER
My commend was changed when submitting. The suggestion to change the file type to ".cmd" was correct; test.vbs as I had it did not work.
VBS code is different to CMD code. The lines that you had originally are a recognisable language for CMD files. If you want to implement it in VBS, you can use either of the VBS code segments that I or psantiangel provided.
Anyway, is it all working for you now? When it connects, does it reference the correct folders?
Regards,
Rob.
Anyway, is it all working for you now? When it connects, does it reference the correct folders?
Regards,
Rob.
ASKER
Conects, etc, but per my posting the file doesn't show up and it hands up at the PORT command. Yes, appears to log in and get to the correct folder (my web guy has this rigged so that with this login ID it takes me directly to the only folder I can access. I own the domain, just do this for simplicity). In summary, everything looks good until the end, and the file has not been transferred. BTW: tried with file name in quotes and not; no difference.
Hmmm, that's odd. When I run a test of just:
Test.cmd
=======
ftp -s:test.scr
=======
Test.scr
=======
open 11.11.11.111
dad@ipstuff.com
abcd1234
put test.pdf
quit
it uploads successfully.
What happens if you go to a command prompt, and type the commands from test.scr manually?
Regards,
Rob.
Test.cmd
=======
ftp -s:test.scr
=======
Test.scr
=======
open 11.11.11.111
dad@ipstuff.com
abcd1234
put test.pdf
quit
it uploads successfully.
What happens if you go to a command prompt, and type the commands from test.scr manually?
Regards,
Rob.
ASKER
I'll try that. Meanwhile, I see that the target file is at the server, but zero bytes. To get out of the PORT command successful step I do a cntl-bk twice, answering 'Y' about halting the batch file. It appears the file name gets created if waiting long enough, but no data transferred.
ASKER
The line "open 11.11.11.111" got a "not recognized as an internal or external command" error.
Type "FTP <enter>" first....then type the commands in the script file...
ASKER
Here's what the script gets:
D:\OCR HOLD1\ftp -s:test.scr
ftp>open 11.11.11.111
Connected to 11.11.11.111
220------------ Welcome to Pure-FTPd [privsep] [TLS] ------
220-You are user number 100 of 400 allowed.
220-Local time is now 17:09. Server port:21
220-This is a private system - No anonymous login
220 You will be disconnected after 15 minutes of inactivity
user <11.11.11.111:<none>>:
331 User dad@ipstuff.com OK. Password required
230-User dad@ipstuff.com has group access to: 48846
230 OK. Current directory is /
ftp> put test.pdf
200 PORT command successful
D:\OCR HOLD1\ftp -s:test.scr
ftp>open 11.11.11.111
Connected to 11.11.11.111
220------------ Welcome to Pure-FTPd [privsep] [TLS] ------
220-You are user number 100 of 400 allowed.
220-Local time is now 17:09. Server port:21
220-This is a private system - No anonymous login
220 You will be disconnected after 15 minutes of inactivity
user <11.11.11.111:<none>>:
331 User dad@ipstuff.com OK. Password required
230-User dad@ipstuff.com has group access to: 48846
230 OK. Current directory is /
ftp> put test.pdf
200 PORT command successful
ASKER
I let the most recent attemp (using .SCR) go until if finally timed out after 4 monutes. At that instant the file name,with zero bytes, popped up on the server.
I'll go try the command line now.
I'll go try the command line now.
ASKER
Manual entry gets the same result: 200 PORT command successful and it waits there.
ASKER
BTW: this seems to be a server side issue, but I note that the uSoft posting mentions all of the OS's it is valid for and Vista is not listed. Could this be a Vista issue?
ASKER
Gotta leave for about 30 minutes.
It *could* be a Vista issue, but I'd be surprised if the FTP architecture changed from XP so as to not allow a flie upload......
Are you able to try it from an XP machine? Or, does using FileZilla or something work from the Vista machine?
Regards,
Rob.
Are you able to try it from an XP machine? Or, does using FileZilla or something work from the Vista machine?
Regards,
Rob.
ASKER
New info: after the manual entry, also stopping at 200 PORT..., I got the following:
Could not open data connection to port 53480: connection timed out.
Could not open data connection to port 53480: connection timed out.
You can try to enter Passive Mode:
Test.scr
=======
open 11.11.11.111
user
dad@ipstuff.com
abcd1234
quote PASV
put test.pdf
quit
Test.scr
=======
open 11.11.11.111
user
dad@ipstuff.com
abcd1234
quote PASV
put test.pdf
quit
ASKER
PASV got "invalid command", whether {PASV} or {"PASV}.
ASKER
OK, you really meant {quote PASV}, which was sussessfull in getting into passive mode, but still hung up with 200 PORT . . . .
ASKER
As before, eventjually got a file named at the server but with zero byes.
Specify the full path of the file you are going to send and add binary, try with pasv and a second time without it
C:\directory\subdirectory\ filename
open 11.11.11.111
user
dad@ipstuff.com
abcd1234
binary
quote PASV
put C:\directory\subdirectory\ test.pdf
quit
C:\directory\subdirectory\
open 11.11.11.111
user
dad@ipstuff.com
abcd1234
binary
quote PASV
put C:\directory\subdirectory\
quit
Can you try another FTP client (such as FileZilla) or a Windows XP desktop?
Rob.
Rob.
ASKER
BTW: I've noticed in looking at the script of the FTP software that it always has a statement like:
Connect socket #900 to 11.11.11.111, port 59375.
Each time the socket # and the port # are different, and the server replies that the data connection has been made.
Connect socket #900 to 11.11.11.111, port 59375.
Each time the socket # and the port # are different, and the server replies that the data connection has been made.
ASKER
Can i control FileZilla within a VBScript?
Not that I know of, but I just wanted to see if another program could do it.....
Did you try psantiangeli's last suggestion?
There is a third-party ActiveX FTP client that you could try:
http://www.chilkatsoft.com/refdoc/xChilkatFtpRef.html
Regards,
Rob.
Did you try psantiangeli's last suggestion?
There is a third-party ActiveX FTP client that you could try:
http://www.chilkatsoft.com/refdoc/xChilkatFtpRef.html
Regards,
Rob.
ASKER
"binary' did not change anything.
I have been using COREFTP to verify. Actually I have been using ABLEFPT 7 for severl weeks, uploading about 40K files per day from six different PCs. THe problem is that ABLE is difficult to get to do what the controls seems to indicate it would do. With as few as three PDs running we often get shut out by the server for having more than 8 connections, but cannot see why that would be. And ABLE is actually just a GUI that manages a java script, so control is very indirect. Looks at WS_FTP and others, but they don't support deleting the local file after it has been uploaded, which is a requirement. So I thought that a VBScript woudl give me more control.
I have been using COREFTP to verify. Actually I have been using ABLEFPT 7 for severl weeks, uploading about 40K files per day from six different PCs. THe problem is that ABLE is difficult to get to do what the controls seems to indicate it would do. With as few as three PDs running we often get shut out by the server for having more than 8 connections, but cannot see why that would be. And ABLE is actually just a GUI that manages a java script, so control is very indirect. Looks at WS_FTP and others, but they don't support deleting the local file after it has been uploaded, which is a requirement. So I thought that a VBScript woudl give me more control.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
On run: "Active X component cannot create object "ChilkatFTP2".
I downloaded the freebe and installed. All looked well. Is this a Vista issue?
I downloaded the freebe and installed. All looked well. Is this a Vista issue?
ASKER
Read Chilkat install material, and ran "regsvr32 chilkatftp.dll" which appeats to have successfully put the Active X control into the registry. However, still getting the same error.
ASKER
Chilkat, Chilkatftp, etc, cannot be found in the registry with a search.
ASKER
It seemed that the object was trying to use the control ChilkatFTP2, and the free version is Chilkat.FTP. Tried it without "2", no luck. So downloaded the not-free ChilkatFTP2 version, and now the object creates. I need PASV mode, so activated the formerly commented-out
ftp.passive = 1
and now I get a run time error "Objec required:ftp".
So, what am I missing now?
ftp.passive = 1
and now I get a run time error "Objec required:ftp".
So, what am I missing now?
ASKER
OK, so looking at the code I changed
ftp.passive = 1
to
objChilkatFTP.passive = 1
and it ran successfully. File now uploaded.
So, remaining question would be how to get the free version to create the object so I don't have to buy the $150 version.
ftp.passive = 1
to
objChilkatFTP.passive = 1
and it ran successfully. File now uploaded.
So, remaining question would be how to get the free version to create the object so I don't have to buy the $150 version.
ASKER
Bottom line: Chilkat shows an example of creating the ChilkatFTP2 object, but not the ChilkatFTP object. Wrote tech support; their policy is they only support the FTP2 version, so don't even disclose how to create the FTP object. Tried registering the DLL, but still won't create.
ASKER
Ah, once again Google to the rescue. Found a posting that showed how to create the object of ChilKatFTP:
Set objChilkatFTP = CreateObject("ChilkatFTP.ChilkatFTP.1")
Note that the demo/unlock statement in the FTP2 demo code is no longer needed, in fact causes an error message; it is not needed because this version is free. So, I have this inside a loop that uploads whatever files it finds in the file upload folder. To share with all, I will post the code with the FTP inside separately.
Set objChilkatFTP = CreateObject("ChilkatFTP.ChilkatFTP.1")
Note that the demo/unlock statement in the FTP2 demo code is no longer needed, in fact causes an error message; it is not needed because this version is free. So, I have this inside a loop that uploads whatever files it finds in the file upload folder. To share with all, I will post the code with the FTP inside separately.
ASKER
'****** MOVE FILES FROM A FLAT FOLDER TO A SERVER
Const strSourceFolderName = "D:\UPLOAD_BUCKET\" ' Where files are
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objChilkatFTP = CreateObject("ChilkatFTP.ChilkatFTP.1")
Set objFolder = objFSO.GetFolder(strSourceFolderName)
objChilkatFTP.Hostname = "ftp.servername.com"
objChilkatFTP.Username = "userid_goes_here_in_quotes"
objChilkatFTP.Password = "PW_goes_here_in_quotes"
objChilkatFTP.Passive = 1 ' Passive
' Connect and login to the FTP server.
intSuccess = objChilkatFTP.Connect()
If (intSuccess <> 1) Then
MsgBox objChilkatFTP.LastErrorText
WScript.Quit
End If
For Each objFile in objFolder.Files ' Now go ftp files
' Upload a file.
strLocalFilename = strSourceFolderName & objFile.Name
strRemoteFilename = objFile.Name
intSuccess = objChilkatFTP.PutFile(strLocalFilename, strRemoteFilename)
If (intSuccess <> 1) Then
MsgBox objChilkatFTP.LastErrorText
WScript.Quit
End If
objFSO.DeleteFile strLocalFilename, True
Next ' Go until empty
objChilkatFTP.Disconnect ' All done; disconnect
ASKER
Thanks Rob. The version I posted uploads a whole folder very nicely. The trouble part was finding how to create an object with the free version of ChilKat; see my posting for explanation.
Regards,
Mike Caldwell
Regards,
Mike Caldwell
Hey Mike, great work!!!! Thanks for pointing us to the free ActiveX control. I didn't notice that before, and didn't find it until I dug around the site a bit.
I'm glad that works! Thanks for posting your code. Thanks for the grade.
Regards,
Rob.
I'm glad that works! Thanks for posting your code. Thanks for the grade.
Regards,
Rob.
you can use the ftp command as described here:
http://support.microsoft.com/kb/96269/en-us