Hey guys. I’m writing this upload/download program in VB6 and I need a little assistance. The program will run, and upload/download, but then it freezes and I need to close it via task manager. The file appears on the client and server, but it is blank, I think because the program crashes. Any suggestions? I put the code below:
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 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 InternetCloseHandle Lib “wininet.dll” (ByVal hInet As Long) As Integer
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 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
Private Sub Command1_Click()
lngINet = InternetOpen(“MyFTP Control”, 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect(lngINet, “ftp.servername.com”, 0, “username”, “password”, 1, 0, 0)
blnRC = FtpGetFile(lngINetConn, “downloadme.txt”, “c:\downloadme.txt”, 0, 0, 1, 0)
‘blnRC = FtpPutFile(lngINetConn, “c:\uploadme.txt”, “uploadme.txt”, 1, 0)
InternetCloseHandle lngINetConn
InternetCloseHandle lngINet
End Sub
Private Sub Command2_Click()
lngINet = InternetOpen(“MyFTP Control”, 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect(lngINet, “ftp.servername.com”, 0, “username”, “password”, 1, 0, 0)
blnRC = FtpPutFile(lngINetConn, “c:\uploadme.txt”, “uploadme.txt”, 1, 0)
‘blnRC = FtpGetFile(lngINetConn, “downloadme.txt”, “c:\downloadme.txt”, 0, 0, 1, 0)
InternetCloseHandle lngINetConn
InternetCloseHandle lngINet
End Sub
As you can see it’s rather simple code. One button uploads and one downloads a file. I can’t figure out why it freezes/crashes. Any ideas?