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: -
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
-
'END DECLARES HERE
-
-
'START SUBS HERE:
-
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
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!
2 1511
Which part of the code freezes tha application . Upload or Download ?
I'm sorry, I figured it out FINALLY! This took me forever to get going. The code is below: -
Const scUserAgent = "vb wininet"
-
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 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 InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
-
-
-
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 = FtpPutFile(hConn, "localfile", "remotefile", FTP_TRANSFER_TYPE_BINARY, 0&)
-
InternetCloseHandle hConn
-
InternetCloseHandle hOpen
-
-
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, "remotefile", "localfile", False, FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_BINARY, 0&)
-
InternetCloseHandle hConn
-
InternetCloseHandle hOpen
-
I guess my constants were off. It's working fast and perfectly now. Thanks anyway!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken Fine |
last post by:
No joy on Macromedia's boards after a few days; maybe someone can help me
here.
I got an excellent string handling function off of planet-source-code.com
that converts text strings to proper...
|
by: Beeman |
last post by:
I am looking for a good control that would display/print JPEG
images in Access 97. The existing Image controls, even with
the JPEG filters, are very slow - and I know there are better
ones out...
|
by: Q. John Chen |
last post by:
I have Vidation Controls
First One: Simple exluce certain special characters:
say no a or b or c in the string:
*
Second One:
I required date be entered in "MM/DD/YYYY" format:
//+4 How...
|
by: RLN |
last post by:
I have an Access2002 database that needs to connect to an Oracle
Database. I connected to my Oracle DB in a simple VB6 app using no ODBC
data source. How do I do the same thing using VBA in...
|
by: thetechturf.com |
last post by:
Ok, here's the deal. I need a script written that will:
Use a regular HTML page and form (I plan to have this in a small box on
all my HTML pages) to submit the information:
Username and...
|
by: DGS |
last post by:
Hi all...
Yesterday I asked about setting a cookie with an intially requested URL that
could be used later. I found the code to do it. For the code on the
login.html page I would like to tweak...
|
by: =?ISO-8859-1?Q?Rog=E9rio_Brito?= |
last post by:
Hi, All.
I'm just getting my feet wet on Python and, just for starters, I'm coding some
elementary number theory algorithms (yes, I know that most of them are already
implemented as modules, but...
|
by: pereges |
last post by:
Ok, I have some problem with arrays which i want to use for storing
rays in my ray tracing project. please have a little patience to read.
I need to fire rays from a a rectangular plane. The rays...
|
by: =?Utf-8?B?QnJ5YW4=?= |
last post by:
Hello group.
I have some code (given to me), but I don't know alot about ASP, so I was
hoping someone here can help. Running on Win 2008 server.
The code below will scan a folder and subfolder...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |