FTP_GetFile

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > FTP (File Transfer Profotol) >

FTP_GetFile

 

Description

 

Gets (downloads) file from FTP server.

 

Syntax

 

n = FTP_GetFile(sFileName, lOptions)

 

Returns

 

Number

A value < 0 indicates an error. Use FTP_GetErrorString(nRet) to get info about the error code

 

Parameters

 

Name

Type

Optional

Meaning

sFileName

String

No

Name of the file to be downloaded.

The file can be also be renamed when it is saved by specifying "oldname:newname" for sFilename

lOptions

Number

No

One of the following two equates indicating download method:

%FTP_SET_SYNC

this option instructs FTP engine to keep control till the file is fully downloaded or an error has occurred
 

%FTP_SET_ASYNC

this option instructs FTP engine to start downloading the file but immediately pass control to the script. In this case programmer is responsible to setup a loop to control download process till file is fully downloaded or an error has occurred
 

 

Remarks

 

Restrictions

 

See also

 

Examples

 

...

'-------------------------------------------------------------------------

'Start DownLoad process Sync mode

'-------------------------------------------------------------------------

'---Sync mode: no way to loop because script execution control

'---will be maintained by FTP_GetFile till download finished or error occurs 

PrintL "---Start downloading in %FTP_SET_SYNC mode----"

FileName = "screen001.jpg"

ftpResult = FTP_GetFile(FileName, %FTP_SET_SYNC)

PrintL "FTP finished is: " + ftpResult

PrintL "----------------------------------------------"

 

'-------------------------------------------------------------------------

'Start DownLoad process Async mode

'-------------------------------------------------------------------------

'---ASync mode: a loop must be setup because script execution control

'---is immediately returned to the script

PrintL "---Start downloading in %FTP_SET_ASYNC mode---"

Dim yPos As Long

FileName = "screen001.jpg"

ftpResult = FTP_GetFile(FileName, %FTP_SET_ASYNC)

PrintL

yPos = Console_GetCursorY

Do

  DoEvents

  PrintAt(FileName & " bytes: " & FTP_GetNumber(%FTP_GET_FILE_BYTES_RCVD), 1, yPos)

Loop while FTP_Finished > 0   ' Loop until end of file reached

 

PrintL "FTP finished is: " + FTP_Finished

PrintL "----------------------------------------------"

...