Automatic file transfer with VB driver PCANywhere

zhaozj2021-02-16  30

Automatic file transfer with VB driver PCANywhere

Pcanywhere allows you to remotely control the PC, just as used as the current computer. It supports a variety of connection: IP connection, MODEM connection, direct connection. In addition to operation, it can also perform file transfer, computer synchronization and other functions. It is the king of the king of the computer remote control.

Pcanywhere is very simple, its use method has a very detailed introduction on the Internet, I will not say more, I will introduce the way to use VB to drive PCANYWHERE.

There is a special application in my project, there are five computers in different places, there is real-time data collection file, I need to go up, download the above data file, these data files have different times. Different, so there is no way to do a fixed automatic file transfer, and I have studied the software to provide Script and Ole white paper, and finally decided to choose OLE.

First, remote connection with OLE

In the ole white paper, write the OLE driver very well, I just make it very clear about my connection code post.

1. Check if modem is in use, because PCANywhere is started, it is no longer controlled by the program, we must check if the MODEM is idle to ensure that the coolder can be successfully plugged. Check if modem idle may be judged by opening whether the serial port in which Modem is located.

2, generate the RemoteDataManager object

3, enter the c: / documents and settings / all users / application data / symantec / pcanywhere, because the configuration file is placed in this directory when the PCANywhere installation is installed, and we can run the run path to this directory, which can be used more conveniently.

4. Generate a RemoteData object, which requires that there is a corresponding CHF file under the configuration file path, which is configured in PCANywhere, as long as the name is the same as the connection method.

5, set the phone number of the coament, set the login username and password, set the ATF file that automatically transfer, and set the Runonnect to True and save this configuration.

6, start the coal and automatically transfer files.

7, delay, determination of whether the MODEM is idle, is idle, this time, the file is transmitted (it is also possible to fail). It is successful if the modified time has been updated. Otherwise it is failed.

8. Release the RemoteData, RemoteDataManager object.

9, unplug a point.

If Checkmodemidle Then

Showbegin 'Show start information

'Crete CremoteDataManager Object

SET RemoteDataManager = CreateObject ("Winawsvr.RemoteDataManager)

RemoteDataManager.changeDirectory "C: / documents and settings / all users / application data / symantec / pcanywhere"

S = remoteDataManager.currentDirectory ()

Chfile = Xprofile.GetValue (WatchPoint (NOWRUNID), "ChFFile") 'Used for the configuration

Set RemoteData = RemoteDataManager.RetrieveObject (chfile, 2, 0)

RemoteData.phonenumber = Xprofile.GetValue (WatchPoint (Nowrunid), "Phonenum") RemoteData.Autoxferfile = filename

RemoteData.autologinname = Xprofile.GetValue (WatchPoint (Nowrunid), "UserName")

RemoteData.autologinpassword = Xprofile.GetValue (WatchPoint (Nowrunid), "PSW")

RemoteData.Runonconnect = TRUE

RemoteData.writeObject (0)

S = RemoteData.phonenumber

RemoteData.launch

Sleep 30000

DO

If Checkmodemidle Then Exit Do

Doevents

Sleep 5000

Loop

'Take the file, you want to perform the transfer process

MoveDbfdata LocalPath

SET RemoteData = Nothing

SET RemoteDataManager = Nothing

NOWRUNID = NOWRUNID 1

END IF

Note: RemoteData, RemoteDataManager objects must be released after it is completed, or there will be misal.

Ok, the drowning automatic file transfer has been implemented, but this file transfer is the unchanged automatic file transfer in PcAnywhere, and cannot achieve the requirements of different documents according to time.

Second, dynamically generate automatic file transfer files

In order to dynamically generate automatic file transfer, naturally modify the configuration of the automatic file transfer file, but there is no function in OLE, I have to take another way.

Use the text editor to open the ATF file (Automatic file transfer file), found that all garbled, only the path can be identified. Ling Machi opened with UltraEdit-32 and opened with hexadecimal, ha, secret is all in it.

The system file format of the ATF is as follows:

04 40 41 54 46 01 00 01 01 00 01 01 01 01 00 01 'The eighth bit: 00 indicates the incremental download, 01 all re-download

00 00 00 00 00 01 00 ff 00 00 11 00 43 'eighth bit: 00 indicates that the file transmission is not hosted, and 01 indicates that the file is transmitted, it does not happen.

41 75 74 6F 58 66 65 72 5F 43 6F 6D 6D 61 6E 64 Autoxfer_Command

01 13 45 3A 5C 55 53 42 42 41 4B 5C 32 30 30 33 First Bit is a transmission mode: 00 Send to host 01 From the host receive 02 Synchronization second bit is the local file path length, which is the local file path

31 2E 64 62 66 14 44 3A 5C 71 74 64 61 74 61 31 'Sixth Host File Path Length, behind the host file path

5C 32 30 30 33 31 2e 64 62 66

With the format of the file, it is not going to generate such a file. Just create this file with a binary method, everything is OK.

Public Sub Maketffile (byval logenagement as string, byval filename as string) DIM TX () AS BYTE

DIM II AS INTEGER

Dim len1, len2 as integer

Len1 = len (localpath)

Len2 = len (RemotePath)

Redim TX (0 to 48 LEN1 LEN2 2)

'04 40 41 54 46 01 00 01 01 00 01 01 01 01 00 01 'eighth bit: 00 indicates incremental download, 01 natural download

'00 00 00 00 00 00 01 00 ff ff 00 00 11 00 43 c

'41 75 74 6F 58 66 65 72 5F 43 6F 6D 6D 61 6E 64 Autoxfer_Command

'01 13 45 3A 5C 55 53 42 42 41 4B 5C 32 30 30 33 First Bit is a transmission mode: 00 Send to host 01 from the host receive 02 Synchronization second bit is the local file path length

'31 2E 64 62 66 14 44 3A 5C 71 74 64 61 74 61 31 'Six host file path length

'5C 32 30 30 33 31 2e 64 62 66

TX (0) = & H4

TX (1) = & H40

TX (2) = & H41

TX (3) = & H54

TX (4) = & H46

TX (5) = & H1

TX (6) = & H0

TX (7) = & H1

TX (8) = & H1

TX (9) = & H0

TX (10) = & H1

TX (11) = & H1

TX (12) = & H1

TX (13) = & H1

TX (14) = & H0

TX (15) = & H1

TX (16) = & H0

TX (17) = & H0

TX (18) = & H0

TX (19) = & H0

TX (20) = & H0

TX (21) = & H0

TX (22) = & H0

TX (23) = & H1

TX (24) = & H0

TX (25) = & HFF

TX (26) = & HFF

TX (27) = & H0

TX (28) = & H0

TX (29) = & h11

TX (30) = & H0

TX (31) = & H43

'41 75 74 6F 58 66 65 72 5F 43 6F 6D 6D 61 6E 64 Autoxfer_Command

TX (32) = & h41

TX (33) = & H75

TX (34) = & H74

TX (35) = & H6F

TX (36) = & H58

TX (37) = & H66

TX (38) = & H65

TX (39) = & H72

TX (40) = & H5F

TX (41) = & H43TX (42) = & H6F

TX (43) = & H6D

TX (44) = & H6D

TX (45) = & h61

TX (46) = & h6e

TX (47) = & H64

'01 13 45 3A 5C 55 53 42 42 41 4B 5C 32 30 30 33 First bit is a transmission method: 00 is sent to host 01 from the main

TX (48) = & H1

TX (49) = len1

For II = 1 to Len1

TX (49 II) = ASC (MID (LocalPath, II, 1))

Next II

TX (49 LEN1 1) = len2

For ii = 1 to len2

TX (49 II LEN1 1) = ASC (MID (RemotePath, II, 1))

Next II

'Binary file open

ON Error ResMe next

Open filename for binary as # 1

For ii = 0 to 48 LEN1 LEN2 2

PUT # 1, TX (II)

Next II

CLOSE 1

End Sub

Enter the local file path, the host file path, the ATF file name, you can generate such a file, then set the transidata.autoxferfile to a newly generated ATF file, you can want to pass what file, but there is a bit Note: These two file paths must exist, otherwise it will be wrong.

Conclusion:

Using VB Drive PCANywhere is a very simple event, but not very good, first it can't complete the program control, or the operation interface when the coament is transmitted, and it cannot be set to a background program, and Artificial intervention is too easy, but it is a very good choice to solve my current problem.

Reference:

"Ole automation.pdf"

转载请注明原文地址:https://www.9cbs.com/read-27237.html

New Post(0)