Home > Software engineering >  Consult: used in the dynamic link library written in VB winnet ftpPutFile function of total failure,
Consult: used in the dynamic link library written in VB winnet ftpPutFile function of total failure,

Time:09-27

Consult everybody, used in VB DLL library winnet. DLL ftpPutfile function always fail when uploading files, use err. LastDllError get error code is 2, but in ordinary exe program that can be normal, part of the program code is as follows:
Const INTERNET_OPEN_TYPE_PRECONFIG=0
Const FTP_TRANSFER_TYPE_UNKNOWN=& amp; H0
Const FTP_TRANSFER_TYPE_ASCII=& amp; H1
Const FTP_TRANSFER_TYPE_BINARY=& amp; The H2
Dim ftpConnState As Boolean
Dim ftpConn As Long
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 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

Establish a connection
'Public Function ftpServer (IP As String, the Port As an Integer, the UserName As the String, PassWord As String) As Boolean
Dim ftpInit As Long
FtpInit=InternetOpen (vbNullString INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0 & amp;)
FtpConn=InternetConnect (ftpInit, IP, Port, UserName, PassWord, 1, 0, 0)
If ftpConn & gt; 0 Then
FtpConnState=True
The Else
FtpConnState=False
End the If
FtpServer=ftpConnState
End the Function
'upload file
The Public Function ftpUploadFile (localPath As String, remotePath As String) As Boolean
If ftpConnState=True Then
FtpUploadFile=FtpPutFile (ftpConn, localPath, remotePath FTP_TRANSFER_TYPE_ASCII, 0)
If Not ftpUploadFile Then
MsgBox Err. Description, Err... LastDllError
End the If
The Else
MsgBox "please confirm the connection"
End the If
End the Function

CodePudding user response:

GetLastError=2 is ERROR_FILE_NOT_FOUND, check your localPath and remotePath is correct!
  •  Tags:  
  • API