Home > Software engineering >  VB to download multiple big BMP file
VB to download multiple big BMP file

Time:09-23

Process is as follows:
Private Sub StartDownLoadBmp ()
Get the client BMP storage location, create a folder
Dim BmpPath, CreateBmpPath
BmpPath=funReadlist (App) Path & amp; "\ info XML", "bmppath")
If BmpPath (0) & lt;> "Wrong" Then
CreateBmpPath=CreatePath (App) Path & amp; "\ the FileInfo \ FileTree XML," (BmpPath (0)))
If CreateBmpPath=True Then
Lblmsg. Caption="create image file folder success"
The Else
Lblmsg. Caption="failed to create image file folder"
The Exit Sub
End the If
End the If
Create the folder 'end
'than FileTree in the image file image file list with local TXT file
Dim GetFileTree, MyFileTxt
Dim GetBmpTime, GetDBTime
Dim ConnectFTP
Dim a, b As Integer
A=0
B=0
GetFileTree=funReadlist (App) Path & amp; "\ the FileInfo \ FileTree XML", "FileNameList")
If GetFileTree (0) & lt;> "Wrong" Then
ConnectFTP=connect to the server (InetDF. RemoteHost, InetDF RemotePort, InetDF. The UserName, InetDF. Password)
The Do While a & lt; UBound (GetFileTree)
MyFileTxt=GetFileToArr (App) Path & amp; "\ the FileInfo " & amp; GetFileTree (a) & amp; ". TXT ")
Dim LineLeft LineRight, FileName As String
The Do While b & lt; UBound (MyFileTxt)
GetBmpTime=""
LineLeft=Split (MyFileTxt (b), "=") (0)
LineRight=Split (MyFileTxt (b), "=") (1)
FileName=Split (LineRight, ""), UBound (Split (LineRight, "")))
GetBmpTime=GetLastTime (BmpPath (0) & amp; "" & amp; GetFileTree (a) & amp; LineLeft & amp; "" & amp; FileName)
If GetBmpTime="" Then
The Debug. Print Trim (" ftp://"& amp; InetDF. RemoteHost & amp; LineRight & amp; ", "& amp; BmpPath (0) & amp; "" & amp; GetFileTree (a) & amp; LineLeft & amp; "" & amp; FileName)
ConnectFTP=download file (Trim (" ftp://"& amp; InetDF. RemoteHost & amp; LineRight), Trim (BmpPath (0) & amp; "" & amp; GetFileTree (a) & amp; LineLeft & amp; "" & amp; FileName))
DoEvents
End the If
B=b + 1
Loop
A=a + 1
Loop
End the If
'than end

End Sub


Module is as follows:
Option Explicit
Private Const INTERNET_OPEN_TYPE_PRECONFIG=0
Private Const INTERNET_OPEN_TYPE_DIRECT=1
Private Const INTERNET_OPEN_TYPE_PROXY=3
Private Declare Function InternetOpen Lib "wininet. DLL" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet. DLL" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As an Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function FtpGetFile Lib "wininet. DLL" Alias "FtpGetFileA" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As a Boolean, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet. DLL" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet. DLL" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet. DLL" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet. DLL" (ByVal hInet As Long) As an Integer
Private Declare Function FtpCreateDirectory Lib "wininet. DLL" Alias "FtpCreateDirectoryA" (ByVal hFtpSession& As a Boolean, ByVal lpszDirectory $)
Dim connection status As Boolean
Dim connection handle As Long


Public Function connect server (IP As String, port As an Integer, the account As String, password As String) As Boolean
Dim initialization As Long
Dim INTERNET_OPEN_TYPE_PRECONFIG As Long
Initialize=InternetOpen (vbNullString INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0 & amp;)
Connection handle=InternetConnect (initialization, IP, port, account number, password, 1, 0, 0)
If the connection handle & gt; 0 Then
Connection status=True
The Else
Connection status=False
End the If
Connect to the server=connection state
End the Function

Public Function to upload files (local path As String, remote path As String) As Boolean
If connection status=True Then
Upload file=FtpPutFile (connection handles, local path, a remote path, 1, 0)
The Else
MsgBox "please confirm the connection" & amp; ": upload a file
"End the If
End the Function

Public Function in the download file (remote path As a String, the local path As String) As Boolean
If connection status=True Then
The download file=FtpGetFile (connection handles, remote path, local path, False, & amp; H80000000, & amp; H0, 0)
The Else
MsgBox "please confirm the connection" & amp; ": download file
"End the If
End the Function

Public Function delete files (ByVal file path) As Boolean
If connection status=True Then
Delete the file=FtpDeleteFile (connection handles, the file path)
The Else
MsgBox "please confirm the connection" & amp; ": delete files
"End the If
End the Function

Public Function to create a directory (ByVal path As String) As String
If connection status=True Then
Create a directory=FtpCreateDirectory (connection handles, path)
The Else
MsgBox "please confirm the connection" & amp; ": create a directory
"nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related