Page 1 of 2 12>
Topic Options
#178800 - 2007-08-07 02:37 PM Problem with ftpget( ) UDF.
Maurits Offline
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.

 Code:
 ;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:
 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 Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
This is what the variable $LocationFile looks like:
 Code:
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 Offline
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 Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Have you run my script?
It returns
 Code:
10

IMHO you should revise your code.

Top
#178910 - 2007-08-08 03:41 PM Re: Problem with ftpget( ) UDF. [Re: Witto]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
bad habbit quoting vars when sending to a udf. (or, so I belive)
 Code:
FTPget("$LocationFile", "$CopyTo", "$gebruikersnaam", "$wachtwoord")


review this:
 Code:
$LocationFile = 10.0.0.1 + Dir("/u/prod/version.*")
;to
$LocationFile = "10.0.0.1" + Dir("/u/prod/verson.*")

correct me if I am wrong.


Edited by Björn (2007-08-08 04:10 PM)
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#178919 - 2007-08-08 05:12 PM Re: Problem with ftpget( ) UDF. [Re: Björn]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
What kind of path and filename is
 Code:
"/u/prod/verson.*"

Anyway, even if you would make it
 Code:
"u:\prod\verson.*"

it would only return you the first hit for a file or foldername starting with
 Code:
verson

per example
 Code:
verson.12345678

that would give you the string
 Code:
10.0.0.1verson.12345678

Top
#178922 - 2007-08-08 05:21 PM Re: Problem with ftpget( ) UDF. [Re: Witto]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe you want to loop for all the hits starting with "verson"
 Code:
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 Offline
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:
 Code:
 
$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 Offline
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 Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I will try to give an example
create a text file
FTPInput.txt
 Code:
open ftp.microsoft.com
user anonymous pass anonymous
cd ResKit/win2000
mget jt.*
y
quit

now perform this command
 Code:
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
#179243 - 2007-08-13 09:26 PM Re: Problem with ftpget( ) UDF. [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
again, a note.
the server host operating system has nothing to do with the issue.
it's ftp and as far as I know, it's standardized stuff.

that's why it has the same name FTP on every platform.
_________________________
!

download KiXnet

Top
#179253 - 2007-08-13 11:42 PM Re: Problem with ftpget( ) UDF. [Re: Lonkero]
Witto Offline
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
#179259 - 2007-08-14 09:09 AM Re: Problem with ftpget( ) UDF. [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Quote:

....
Dir() lists files and directories on a (windows) file system, not on a FTP server.
....


On an FTP server dir can be used to show a list of files just like on a command prompt in Windows.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179260 - 2007-08-14 10:05 AM Re: Problem with ftpget( ) UDF. [Re: Mart]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Mart,
Can/would you use the Dir() function to list the files on an FTP server?
 Originally Posted By: Mauritz27
FTPget("10.0.0.1" + Dir("/u/prod/version.*"), "$CopyTo", "$gebruikersnaam", "$wachtwoord")

Top
#179264 - 2007-08-14 10:48 AM Re: Problem with ftpget( ) UDF. [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yeah. :P
_________________________
!

download KiXnet

Top
#179265 - 2007-08-14 11:18 AM Re: Problem with ftpget( ) UDF. [Re: Lonkero]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You mean noh or doh or something like that ;\)
Top
#179266 - 2007-08-14 11:32 AM Re: Problem with ftpget( ) UDF. [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
exactly.
just had a conversation with a woman last night about my conversational skills.
well, I think, if I say a word like "yeah", anyone can read what let me to say it and what I really mean with it.
and here the point was proven.

on the other hand, I was thinking more like "yeah, just like witto said. he's my sheep!" but, same effect after all... \:\)
_________________________
!

download KiXnet

Top
#179267 - 2007-08-14 12:23 PM Re: Problem with ftpget( ) UDF. [Re: Lonkero]
Richard H. Administrator Offline
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.

 Code:
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
#179268 - 2007-08-14 12:47 PM Re: Problem with ftpget( ) UDF. [Re: Richard H.]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Great,
That gives a list that can be queried. Now just look for all the files that start with "version" and download them with ftpget()

Top
#179270 - 2007-08-14 01:43 PM Re: Problem with ftpget( ) UDF. [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: Witto
Mart,
Can/would you use the Dir() function to list the files on an FTP server?
 Originally Posted By: Mauritz27
FTPget("10.0.0.1" + Dir("/u/prod/version.*"), "$CopyTo", "$gebruikersnaam", "$wachtwoord")


That’s not what I meant. FTP has a dir command build in. Never tried the kix Dir() on a FTP server but my guess is it wont work.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.047 seconds in which 0.02 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org