OPENHOST is used to connect to an FTP server
Syntax:
OPENHOST(server,user,password)
- server: DNS name or IP address of the FTP server.
- user (optional): user name for the login.
- password (optional): login password.
Remarks:
- Use SETPROTOCOL before calling OPENHOST if you want to use secure FTP.
- If no user name and password are supplied ScriptFTP will try to login anonymously.
- If you do not want your FTP password to show up in clear text you can encrypt the entire script file. See Encrypting script files.
Return value:
OPENHOST will return “OK” as soon as the login has been successful and the connection is established.
If the operation fails it will return an error code. You may check the return value in order to try again. See Error handling or the last example on this page.
See also:
CLOSEHOST
SETPROTOCOL
SETPORT
SETTYPE
SETPASSIVE
Examples:
# Connect to ftp.myhost.com as myuser and download all the files OPENHOST("ftp.myhost.com","myuser","mypassword") GETFILE("*.*") CLOSEHOST # Connect to ftp.funet.fi anonymously, download README # and then upload it to ftp.myhost.com # The file will be downloaded to the Windows temp directory LOCALCHDIR("C:\WINDOWS\TEMP")
OPENHOST("ftp.funet.fi") GETFILE("README") CLOSEHOST
OPENHOST("ftp.myhost.com","myuser","mypassword") PUTFILE("README") CLOSEHOST # Delete the downloaded README file EXEC("del README")
# This is a label marking a specific location in the script. :start # Connect to FTP server $result=OPENHOST("ftp.myhost.com","myuser","mypassword") # Check if OPENHOST has failed IF($result!="OK") PRINT("Error. Cannot connect to FTP server.") # Wait 1 second SLEEP(1) # Retry GOTO :start END IF # Once ScriptFTP reaches this point # it is connected to the FTP server # Download notes.doc GETFILE("notes.doc") # Close the connection CLOSEHOST