|
|
|
|
|
- Implementation
- Details of different steps
- Step 1: Establishing a connection with a WINDEV RPC or FTP server
- Step 2: Transmitting a file to a WINDEV FTP server
- Step 3: Retrieving a file from a WINDEV FTP server
- Step 4: Closing a connection with a WINDEV RPC or FTP server
Detailed use of WINDEV FTP/RPC
To upload and download files, you must comply with the following rules: - Connect to a WINDEV FTP server with NetConnect. This function establishes a connection between WINDEV and the server and it provides a connection identifier.
- Upload, download files.
- Close the connection to the server with NetDisconnect.
Remarks: - The TCP/IP communication protocol must be installed and an IP address must be defined.
- To create a WINDEV FTP/RPC server, all you have to do is use NetStartServer.
Details of different steps Step 1: Establishing a connection with a WINDEV RPC or FTP server To transfer files, a connection must be established to a WINDEV RPC or FTP server. The connection is established by NetConnect. The code for establishing a connection must be found before the first "Net" function. The value returned by NetConnect must be stored because this one will be used by the other "RPC" and "FTP" functions. The code used to connect to an RPC server is as follows: FUNCTION RPCConnection (Address, User, Password)
ConnectionNum is int
ConnectionNum = NetConnect(Address, RPCServer, User, Password)
RETURN ConnectionNum
Remark: How to create a WINDEV RPC or FTP server? To create a WINDEV RPC or FTP server, you must create an application that uses NetStartServer to start the server. NetEndServer is used to stop this server. The WDRPCSRV.INI file that contains the connection rights granted to the users. This text file and the WINDEV RPC/FTP server are found in the same directory. It must contain a "password" section in which each entry point is a username: [Passwords] UserName1=Password1 UserName2=Password2 UserName3=Password3 ... Remarks: - The server must be accessible by all the client computers (by TCP/IP).
- To be accessible, the server must be started.
Step 2: Transmitting a file to a WINDEV FTP server In the following example, a file is transmitted to the WINDEV FTP server ( NetSendFile). A progress bar is used to track the progress of the transfer.
GLOBAL
Transfer_Completed is boolean = False
Transfer_InProgress is boolean = False
Event("ProgBar_Transfer", "RPCClient", "SendFile")
...
ConnectFTP is int = NetConnect("148.61.125.245", FTPServer, "GUEST", "")
...
IF Transfer_InProgress = True THEN
Error("A file transfer is in progress")
ELSE
Transfer_Completed = False
Transfer_InProgress = True
IF NetSendFile(ConnectFTP, "C:\autoexec.bat", "C:\autoexec.cli", ...
"SendFile", 10) = False THEN
Info("The transfer failed")
END
...
END
PROCEDURE ProgBar_Transfer
Message("Transfer in progress")
ProgressBar(_EVE.wParam, _EVE.lParam)
IF _EVE.wParam = _EVE.lParam THEN
Transfer_InProgress = False
Transfer_Completed = True
Message("Transfer completed")
Info("Transfer completed")
END
Step 3: Retrieving a file from a WINDEV FTP server NetGetFile is used to retrieve a file found on the WINDEV FTP/RPC server. Remark: it is possible to easily find out the list of directories and files on a WINDEV FTP server.. An example is available in the description of NetDirList.
GLOBAL
WM_MYMESSAGE is int
lpString is string fixed on 20 = "ProgBar_Main"
ConnectFTP is int
ConnectFTP = NetConnect("148.61.125.245", FTPServer, "GUEST", "")
WM_MYMESSAGE = CallDLL32("USER32", "RegisterWindowMessageA", &lpString)
Event("UPDProgBar", "MAIN", WM_MYMESSAGE)
HourGlass(True)
IF NOT NetGetFile(ConnectFTP, "C:\autoexec.bat", "C:\autoexec.cli", WM_MYMESSAGE, 10) THEN
Error("Error while transferring the file")
END
HourGlass(False)
PROCEDURE UPDProgBar()
IF _EVE.wParam = _EVE.lParam THEN
ProgressBar()
ELSE
ProgressBar(_EVE.wParam, _EVE.lParam, "Transfer in progress")
END
Step 4: Closing a connection with a WINDEV RPC or FTP server Once the files have been transferred, you must disconnect from the WINDEV RPC or FTP server. The disconnection is performed by NetDisconnect. The disconnection code must be found after the last "Net" statement. The "ConnectionNum" variable, required for the disconnection, contains the value returned by NetConnect.
The code used to disconnect from a WINDEV RPC server is as follows:
NetDisconnect(ConnectionNum)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|