; *****************************************************
; Example65.ftp
; =============
; This example demonstrates the new FORM functions
; in more deepth. It allows you to select a FTP Server
; for you to browse on and select files for download.
; It will then display the progress of the download
; in a seprate form, allowing you to CANCEL the
; transfer at any time.
; - Examples 64 through 69 demonstrate the use of the
; various capabilities of FORMS and their interacation
; with your scripts.
;
; ---
;
; This demo simply accepts the FTP Server to browse as
; well as your username and password to access the server.
; Please execute this example and then view the source
; of the FORM files use. They are called:
; pgFTPLogin.html
; pgFileProgress.html
; located in the HTMLS folder.
; You will see that the "Names" of the input fields in those
; sources have the same name as the variables:
; varFTPServer
; varFTPPort
; varPassive
; varUsername
; varPassword
; varButtonSubmit
; varButtonCancel
;
; varCount
; varNumber
; varCurrentFile
; in this script. This fact is the key to the interaction
; between your scripts and your HTML forms.
;
; NOTE: In the HTML sources we may "link" to subroutines
; in this script by creating a HyperLink with a "gosub:"
; prefix. F.ex. a hyperlink: gosub:CancelDownload will trigger
; the subroutine called "CancelDownload" and stop the download
; of the selected files. Please view both the script as well
; as the HTML sources for more details.
;
; -----------------------------------------------------------
; Commands demonstrated:
;
; OpenForm : Opens a modal FORM and stops execution
; of the script until the FORM is closed.
;
; ShowForm : Shows a FORM and continues execution.
;
; UpdateForm : Updates the FORM being showed. If you
; change a variable with the same name as
; one of the widgets on the FORM this
; statement will reflect that change.
;
; CloseForm : Closes the current form.
;
; Break : Breaks OUT of a "For"..."Next" loop.
;
; HideVariable : Prevents variable content from
; displaying. Used to hide f.ex.
; Password variables.
;
; LetHidden : Same as LET but hides the actual
; value being assigned to the variable.
;
; Syntax:
; OpenForm "<HTML Filename>"
; ShowForm "<HTML Filename>"
; UpdateForm
; CloseForm
; Break <Loop-variable>
; HideVariable "VariableName"
; LetHidden <Variable>=<Value>
;
; -----------------------------------------------------------
; NOTE: You are be able to execute this example unchanged.
; ***********************************************************
; -- Hide the window while accepting input from user
ToggleWindowOff
; -- Hide all password variables. Those will not be logged.
HideVariable varPassword
NumVariable i
Let Cancelling=false
; -- Initialize the Page values
Let varFTPServer="www.ftp-performer.com"
Let varFTPPort="21"
Let varPassive="ON"
Let varUsername="anonymous"
LetHidden varPassword="perform@"
Let varButtonSubmit="Connect"
Let varButtonCancel=""
; -- Set the form properties like position and sizes
Let FormLeft=0
Let FormTop=0
Let FormWidth=500
Let FormHeight=500
Let FormCentered=True
; -- While hovering over hyperlinks, display the link on the bottom
; of the window
Let FormDisplayLinks=True
; -- Now open the Form
OpenForm "%%Ftpctrldir%%\Htmls\pgFTPLogin.html"
; -- If the "Submit" button was pressed...
if "%%varButtonSubmit%%x" = "Submitx" then
Host="%%varFTPServer%%"
User="%%varUsername%%"
Password="%%varPassword%%"
Port="%%varFTPPort%%"
if "%%varPassive%%x" = "ONx" then
PassiveON
Else
PassiveOFF
endif
Connect
; -- Open a remote file-dialog and allow users to select files
; for download.
Remote-FileDialog
; -- Did the user select any file(s) ?
if %%RemoteSelectedCount%% > 0 then
; -- Select a location on the local computer where the
; downloaded files will be saved.
Local-FolderDialog LocalFolder
if "%%LocalFolder%%x" != "x" then
Local-CD "%%LocalFolder%%"
; -- The "varDest" variable will be diwplayed in the FORM showing
; the download progress...
Let varDest = "%%LocalFolder%%"
Remote-CD "%%RemoteSelectedDir%%"
; -- Set the form properties like position and sizes
Let FormWidth=600
Let FormHeight=370
Let FormCentered=True
; -- While hoevering over hyperlinks, display the link on the bottom
; of the window
Let FormDisplayLinks=True
; -- The "varCount" and "varNumber" variables will be displayed in
; the FORM showing the download progress...
NumVariable varCount
NumVariable varNumber
; -- Now open the Download Progress FORM
ShowForm "%%Ftpctrldir%%\Htmls\pgFileProgress.html"
Let varNumber = %%RemoteSelectedCount%%
; -- Start retrieving the selected list of files
for i = 1 to %%RemoteSelectedCount%%
if %%Cancelling%% = true then
break i
endif
; -- The "varCurrentFile" variable will be displayed in
; the FORM showing the download progress...
Let varCurrentFile = "%%RemoteSelectedFile_[%%i%%]%%"
Let varCount=%%i%%
; -- Reflect the variable changes in the progress FORM...
UpdateForm
; -- Downbload the file ...
Get "%%RemoteSelectedFile_[%%i%%]%%"
next i
CloseForm
endif
endif
; -- Restore window to show the progress...
; Restore
Disconnect
else
Message "Cancelled."
endif
EndScript
; -- This subroutine, DisplayFields, is called from within the
; pgFTPLogin.html FORM if the user clicks the "DisplayValues" link.
:DisplayFields
Message "Server: %%varFTPServer%%//13//Username: %%varUsername%%//13//Password: %%varPassword%%//13//Passive: %%varPassive%%"
Return
; -- This subroutine, CancelDownload, is called from within the
; pgFileProgress.html FORM if the user clicks the "Cancel" link.
:CancelDownload
; -- CancelTransfer will cancel the currently downloaded file.
CancelTransfer
Let Cancelling=true
Return