台灣最大程式設計社群網站
線上人數
1181
 
會員總數:246134
討論主題:189714
歡迎您免費加入會員
討論區列表 >> VB.NET >> vb.net使用wininet.dll InternetConnect 結果為0問題
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
vb.net使用wininet.dll InternetConnect 結果為0問題
價值 : 50 QP  點閱數:103 回應數:0
樓主

青仔
初學者
15 21
385 37
發送站內信

Hi VB.net 的前輩大家好:

小弟使用wininet.dll做檔案的上傳/下傳,程式執行InternetOpen的結果不為0,是正常的,但執行Dim hConnect As Integer = InternetConnect(hInternet, ip, INTERNET_DEFAULT_FTP_PORT, User, PassWd, 1, 0, 0),hConnect的結果為0,導致連線不成功,但在vb6確實是可正常連線的,請各位前輩,可以幫我看一下,程式該怎麼調整嗎?謝謝!

Public Class Form1
Dim ip As String
Dim INTERNET_DEFAULT_FTP_PORT As String
Dim User As String
Dim PassWd As String
Dim SourcePath As String
Dim TerminalPath As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ip = "XXX.XXX.XX.XX"
INTERNET_DEFAULT_FTP_PORT = 21
User = "XXXX"
PassWd = "XXX"
Call PutFile()
End Sub


Private Sub Getfile()

Dim hInternet As Integer = InternetOpen("", 1, vbNullString, vbNullString, 0)
Dim hConnect As Integer = InternetConnect(hInternet, ip, INTERNET_DEFAULT_FTP_PORT, User, PassWd, 1, 0, 0)
If hConnect = 0 Then Exit Sub
Dim lRet As Boolean = FtpGetFile(hConnect, SourcePath, TerminalPath, 0, 0, 0, 0)
InternetCloseHandle(hConnect)
InternetCloseHandle(hInternet)

End Sub

Private Sub Putfile()

Dim hInternet As Integer = InternetOpen("", 1, vbNullString, vbNullString, 0)
Dim hConnect As Integer = InternetConnect(hInternet, ip, INTERNET_DEFAULT_FTP_PORT, User, PassWd, 1, 0, 0)
If hConnect = 0 Then MsgBox("沒連上主機") : Exit Sub
Dim lRet As Boolean = FtpPutFile(hConnect, SourcePath, TerminalPath, 0, 0, 0, 0)
InternetCloseHandle(hConnect)
InternetCloseHandle(hInternet)

End Sub

End Class

module:

Public 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

Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String,
ByVal nServerPort As Integer, ByVal sUsername As String,
ByVal sPassword As String, ByVal lService As Long,
ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String,
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean,
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long,
ByVal dwContext As Long) As Boolean

Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Integer, ByVal lpszRemoteFile As String,
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean,
ByVal dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer,
ByVal dwContext As Integer) As Boolean


Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean

Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

搜尋相關Tags的文章: [ wininet ] , [ InternetConnect ] ,
本篇文章發表於2020-10-28 09:59
目前尚無任何回覆
   

回覆
如要回應,請先登入.