Question Locked

File upload/download in VB6

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Hey all. I've been pouring over forums and google concerning uploading/downloading files to/from my web server using VB6. I've seen many articles, but none on bypassing FTP commands and using VB straight to HTTP server. I bet it can be done, but I can't seem to make it work. Anyone done this before or have a good idea how to do it? I can provide all necessary credentials to VB if needed. It's a dummy account on the web server anyway. Any help would be greatly appreciated. Thanks!

4 replies

by dlandmesser

Well, I made some progress. I can download easily, but I still need a function to upload. Here is the code so far:

Const INTERNET_SERVICE_FTP = 1

Const INTERNET_OPEN_TYPE_DIRECT = 1

Const INTERNET_FLAG_PASSIVE = &H8000000

Const FTP_TRANSFER_TYPE_BINARY = 0

Const FILE_ATTRIBUTE_ARCHIVE = &H20

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 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 Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Private Sub Command1_Click()

Dim hOpen&, hConn&

Dim lRes As Long

hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)

hConn = InternetConnect(hOpen, "ftp.thelwcf.com", "21", "(username)", "(password)", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)

lRes = FtpGetFile(hConn, "index.html", "C:\index.html", False, FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_BINARY, 0&)

InternetCloseHandle hConn

InternetCloseHandle hOpen

End Sub

As you can see, it's simple enough. One command button to do the work. I just need one more function to allow the uploading. Any help would be more than appreciated. Thanks in advance.

by dawgit

Are you useing .NET to do some web work? Normaly you wouldn't be doing web programing in VB (HTTP server) Well I wouldn't anyway. So help us out here on just what it is you are wanting to do. -d

by dlandmesser

Well, I want to upload and download files to and from an FTP server. I can download, but I need another function to allow the upload. Any guess?

This discussion is closed to new replies.