Hey guys. I have this upload/download VB code that sort of works. When I run it, it will upload/download the file, but then it freezes and I need to close the app. Can anyone see why? I have the code below:
START DECLARES HERE:
[code=vb]
Private Declare Function InternetOpen Lib "wininet.dl l" Alias "InternetOp enA" (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.dl l" Alias "InternetConnec tA" (ByVal hInternetSessio n 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 InternetCloseHa ndle Lib "wininet.dl l" (ByVal hInet As Long) As Integer
Private Declare Function FtpPutFile Lib "wininet.dl l" Alias "FtpPutFile A" (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.dl l" Alias "FtpGetFile A" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttri butes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
'END DECLARES HERE
'START SUBS HERE:
Private Sub Command1_Click( )
lngINet = InternetOpen("M yFTP Control", 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect (lngINet, "ftp.servername .com", 0, "username", "password", 1, 0, 0)
blnRC = FtpGetFile(lngI NetConn, "downloadme.txt ", "c:\downloadme. txt", 0, 0, 1, 0)
'blnRC = FtpPutFile(lngI NetConn, "c:\uploadme.tx t", "uploadme.t xt", 1, 0)
InternetCloseHa ndle lngINetConn
InternetCloseHa ndle lngINet
End Sub
Private Sub Command2_Click( )
lngINet = InternetOpen("M yFTP Control", 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect (lngINet, "ftp.servername .com", 0, "username", "password", 1, 0, 0)
blnRC = FtpPutFile(lngI NetConn, "c:\uploadme.tx t", "uploadme.t xt", 1, 0)
'blnRC = FtpGetFile(lngI NetConn, "downloadme.txt ", "c:\downloadme. txt", 0, 0, 1, 0)
InternetCloseHa ndle lngINetConn
InternetCloseHa ndle lngINet
End Sub[/code]
Basically one button uploads, and the other downloads a file. It will create the file, but nothing is in the file. Then it craps out and I need to terminate the whole program. Any guesses? Thanks in advance!
START DECLARES HERE:
[code=vb]
Private Declare Function InternetOpen Lib "wininet.dl l" Alias "InternetOp enA" (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.dl l" Alias "InternetConnec tA" (ByVal hInternetSessio n 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 InternetCloseHa ndle Lib "wininet.dl l" (ByVal hInet As Long) As Integer
Private Declare Function FtpPutFile Lib "wininet.dl l" Alias "FtpPutFile A" (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.dl l" Alias "FtpGetFile A" (ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttri butes As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
'END DECLARES HERE
'START SUBS HERE:
Private Sub Command1_Click( )
lngINet = InternetOpen("M yFTP Control", 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect (lngINet, "ftp.servername .com", 0, "username", "password", 1, 0, 0)
blnRC = FtpGetFile(lngI NetConn, "downloadme.txt ", "c:\downloadme. txt", 0, 0, 1, 0)
'blnRC = FtpPutFile(lngI NetConn, "c:\uploadme.tx t", "uploadme.t xt", 1, 0)
InternetCloseHa ndle lngINetConn
InternetCloseHa ndle lngINet
End Sub
Private Sub Command2_Click( )
lngINet = InternetOpen("M yFTP Control", 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect (lngINet, "ftp.servername .com", 0, "username", "password", 1, 0, 0)
blnRC = FtpPutFile(lngI NetConn, "c:\uploadme.tx t", "uploadme.t xt", 1, 0)
'blnRC = FtpGetFile(lngI NetConn, "downloadme.txt ", "c:\downloadme. txt", 0, 0, 1, 0)
InternetCloseHa ndle lngINetConn
InternetCloseHa ndle lngINet
End Sub[/code]
Basically one button uploads, and the other downloads a file. It will create the file, but nothing is in the file. Then it craps out and I need to terminate the whole program. Any guesses? Thanks in advance!
Comment