#178800 - 2007-08-07 02:37 PM
Problem with ftpget( ) UDF.
|
Maurits
Fresh Scripter
Registered: 2007-04-23
Posts: 16
Loc: The Netherlands
|
Hello readers,
I have a problem with ftpget() udf. Maybey you can help me.
Here is the UDF I want to use from Lonkero and Kdyer.
;Function: FTPget()
;
;Authors: Lonkero
; kdyer
;
;Version: 1.2 (2th of August 2007)
;
;Version History:
; 1.2 - current, added Force-parameter
; 1.1 (6th of December 2002)
;
;Action: gets file from ftp or http server and saves it in specified file
;
;Syntax: FTPget("URL", "TARGET", "USERNAME", "PASSWORD", FORCE)
;
;Parameters:
; URL - full url to the file to get
; TARGET - full path to file where to save
; USERNAME- optional, specifies username to use in connection
; PASSWORD- optional, specifies password to use in connection
; FORCE - optional, force udf to bypass cache
;
;Returns:
; Nothing or errorcode on error.
;
; on error errorcodes returned and set:
; 1 -failed to initialize http-object
; 2 -failed to initialize ADODB-object
; 3 -failed to open connection
; 4 -ADO write failed
; 5 -save to file failed
;
;Dependencies:
; IE5 or higher
;
;Remarks:
; if file exists, it will be overwritten.
; not sure about the ado, dependency?
;
;Example:
; "Downloading TypelibViewer, Please standby..."
; if FTPget("http://www.rwksystems.com/files/TypeLibViewer.exe","%temp%\typelibViewer.exe")
; "error occured:" @error
; else
; "Download complete. file is saved in %temp% as typelibViewer.exe"
; endif
;
;Source:
Function FTPget($sURL, $sTargetFile, optional $sUser, $sPass, $iForce)
Dim $oFTP, $oStream,$dwSM,$,$sLoc
$sLoc="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$sUser=""+$sUser
if $iForce
$dwSM = Readvalue($sLoc,"Syncmode5")
$=writevalue($sLoc,"Syncmode5",3,"REG_DWORD")
endif
$oFTP = CreateObject("Microsoft.XMLHTTP")
if @error
$ftpget=1
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 1
endif
$oStream = CreateObject("ADODB.Stream")
if @error
$ftpget=2
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 2
endif
if $sUser
$oFTP.Open("GET", $sURL, not 1, $sUser, $sPass)
else
$oFTP.Open("GET", $sURL, not 1)
endif
if @error
$ftpget=3
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 3
endif
$oFTP.Send
$oStream.Type = 1
$oStream.Mode = 3
$oStream.open
$oStream.Write($oFTP.responseBody)
if @error
$ftpget=4
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 4
endif
$oStream.SaveToFile($sTargetFile, 2)
if @error
$ftpget=5
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
exit 5
endif
$oFTP=0
if $iForce
$=writevalue($sLoc,"Syncmode5",$dwSM,"REG_DWORD")
endif
$oStream.Close
EndFunction
To run this UDF I am using the following code:
$LocationFile = 10.0.0.1 + Dir("/u/prod/version.*")
$CopyTo = $locatie + "\temp\" + @WKSTA
$gebruikersnaam = "user"
$wachtwoord = "123456"
CALL \\server\netlogon\ftpget.udf
FTPget("$LocationFile", "$CopyTo", "$gebruikersnaam", "$wachtwoord")
The problem is that I cant extract the version file from te linux ftp server. I know that is has something to do with $LocationFile.
I think that the problem would be solved if I could make an connection firs en with an second option specify the location of the file.
(The reason why I want to download this version file is to see if the client computer needs an update.)
|
Top
|
|
|
|
#178803 - 2007-08-07 03:35 PM
Re: Problem with ftpget( ) UDF.
[Re: Maurits]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
This is what the variable $LocationFile looks like:
Break On
$LocationFile = 10.0.0.1 + Dir("/u/prod/version.*")
$LocationFile ?
Get $SO
|
Top
|
|
|
|
#178853 - 2007-08-08 08:48 AM
Re: Problem with ftpget( ) UDF.
[Re: Witto]
|
Maurits
Fresh Scripter
Registered: 2007-04-23
Posts: 16
Loc: The Netherlands
|
The variable $LocationFile looks like this: 10.0.0.1/u/prod/version.12345678 and after a few months the version wil be version.12345679
I get error 3 when running the script. That would mean that I't couldn't download the file.
Edited by Maurits27 (2007-08-08 09:21 AM)
|
Top
|
|
|
|
#178881 - 2007-08-08 01:01 PM
Re: Problem with ftpget( ) UDF.
[Re: Maurits]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Have you run my script? It returns
IMHO you should revise your code.
|
Top
|
|
|
|
#178919 - 2007-08-08 05:12 PM
Re: Problem with ftpget( ) UDF.
[Re: Björn]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
What kind of path and filename is
Anyway, even if you would make it
it would only return you the first hit for a file or foldername starting with
per example
that would give you the string
|
Top
|
|
|
|
#178922 - 2007-08-08 05:21 PM
Re: Problem with ftpget( ) UDF.
[Re: Witto]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Maybe you want to loop for all the hits starting with "verson"
Break On
$LocationFile = Dir("u:\prod\verson.*")
Do
$LocationFile ?
$LocationFile = Dir()
Until @ERROR
Get $SO
|
Top
|
|
|
|
#179226 - 2007-08-13 12:11 PM
Re: Problem with ftpget( ) UDF.
[Re: Witto]
|
Maurits
Fresh Scripter
Registered: 2007-04-23
Posts: 16
Loc: The Netherlands
|
Thanks for all the help so far.
Everyone seems to forget that we are making a connection to a linux server. I know for sure that the problem is that the script cant find the location of the file. This file I want to download from the linux ftp server. The code that should be adjusted is: Dir("/u/prod/version.*")
The problem is that first the ftp connection should be open. And after the connection is made I would like to say where the file should be downloaded.
I don't know is the function ftpget() can be used for my cause.
This is my code so far:
$CopyTo = $locatie + "\temp\" + @WKSTA
$gebruikersnaam = "user"
$wachtwoord = "123456"
CALL \\server\netlogon\ftpget.udf
FTPget("10.0.0.1" + Dir("/u/prod/version.*"), "$CopyTo", "$gebruikersnaam", "$wachtwoord")
? "$CopyTo"
|
Top
|
|
|
|
#179232 - 2007-08-13 02:50 PM
Re: Problem with ftpget( ) UDF.
[Re: Maurits]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I don't think you will be able to use the Dir() function for that. I think you want to
- open the site 10.0.0.1
- go to the location /u/prod/
- do a mget of the file(s) version.*
Maybe you can try to create an input file for the FTP command.
|
Top
|
|
|
|
#179238 - 2007-08-13 05:43 PM
Re: Problem with ftpget( ) UDF.
[Re: Maurits]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I will try to give an example create a text file FTPInput.txt
open ftp.microsoft.com
user anonymous pass anonymous
cd ResKit/win2000
mget jt.*
y
quit
now perform this command
ftp -n -s:C:\PathTo\ftpinput.txt
You will see that jt.zip is downloaded to your current directory. Here is some documentation from Microsoft Using FTP Batch Scripts
Edited by Witto (2007-08-13 06:20 PM) Edit Reason: Added link to Microsoft KB article
|
Top
|
|
|
|
#179253 - 2007-08-13 11:42 PM
Re: Problem with ftpget( ) UDF.
[Re: Lonkero]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I think the issue is the way the Dir() function is used. Dir() lists files and directories on a (windows) file system, not on a FTP server. Like Jooel says, ftp is standardized. it works (almost) the same on a windows server as ona a Unix or Linux server. Maybe except for those things that are filesystem specific.
- On Windows, "directory" is the same as "Directory"
- Unix/Linux is CaSe SeNsItIvE, "directory" and "Directory" will be different
- On Windows,
cd ResKit/win2000 and cd ResKit\win2000 both work - On Unix/Linux, I presume only forward slashes ("/") are valid
|
Top
|
|
|
|
#179265 - 2007-08-14 11:18 AM
Re: Problem with ftpget( ) UDF.
[Re: Lonkero]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
You mean noh or doh or something like that
|
Top
|
|
|
|
#179267 - 2007-08-14 12:23 PM
Re: Problem with ftpget( ) UDF.
[Re: Lonkero]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
To get a directory list you just need to get the HTML page and parse it.
Here is a rough example adapted from FTPGet() - you may need to change the parsing rules depending on the response from the Web server.
Note, there is no sanity checking on the path or the returned data type. GIGO.
Break ON
$=SetOption("Explicit","ON")
Dim $sFile,$sFileList,$sURL
$sURL="ftp://ftp.microsoft.com/deskapps"
$sFileList=FTPDir($sURL)
If $sFileList
"Entries in "+$sURL+":"+@CRLF
For Each $sFile in Split($sFileList,@CRLF)
$sFile+" is a "+IIf(Right($sFile,1)="/","DIRECTORY","FILE")+@CRLF
Next
Else
"There are no entries in "+$sURL+@CRLF
EndIf
Function FTPDir($sURL,Optional $sUser, $sPass, $iForce)
Dim $oFTP,$,$iERROR,$sLine,$iParse,$sLoc,$dwSM
$iERROR=0
$iParse=0
$sLoc="HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$sUser=""+$sUser
If $iForce
$dwSM = Readvalue($sLoc,"Syncmode5")
$=writevalue($sLoc,"Syncmode5",3,"REG_DWORD")
EndIf
$oFTP = CreateObject("Microsoft.XMLHTTP")
If @error $ftpget=1 Else
If $sUser $oFTP.Open("GET", $sURL, Not 1, $sUser, $sPass) Else $oFTP.Open("GET", $sURL, Not 1) EndIf
If @error $ftpget=3 Else
$oFTP.Send
For Each $sLine in Split($oFTP.responseBody,@CRLF)
Select
Case InStr($sLine,"<PRE>") $iParse=1
Case InStr($sLine,"</PRE>") $iParse=0
Case $iParse
$sLine=Split($sLine+'<A HREF="','<A HREF="')[1]
$sLine=Split($sLine,'"')[0]
If $sLine $FTPDir=$FTPDir+@CRLF+$sLine EndIf
EndSelect
Next
EndIf
EndIf
$oFTP=0
If $iForce $=WriteValue($sLoc,"Syncmode5",$dwSM,"REG_DWORD") EndIf
$FTPDir=SubStr($FTPDir,3)
Exit $iERROR
EndFunction
;
; vim: ts=4 sw=4 ai filetype=kix
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|