473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need a little code tweak

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:
Expand|Select|Wrap|Line Numbers
  1. 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
  2. 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
  3. Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
  4. 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
  5. 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
  6. 'END DECLARES HERE
  7.  
  8. 'START SUBS HERE:
  9. Private Sub Command1_Click()
  10. lngINet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)
  11. lngINetConn = InternetConnect(lngINet, "ftp.servername.com", 0, "username", "password", 1, 0, 0)
  12. blnRC = FtpGetFile(lngINetConn, "downloadme.txt", "c:\downloadme.txt", 0, 0, 1, 0)
  13. 'blnRC = FtpPutFile(lngINetConn, "c:\uploadme.txt", "uploadme.txt", 1, 0)
  14.  
  15. InternetCloseHandle lngINetConn
  16. InternetCloseHandle lngINet
  17.  
  18. End Sub
  19.  
  20. Private Sub Command2_Click()
  21. lngINet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)
  22. lngINetConn = InternetConnect(lngINet, "ftp.servername.com", 0, "username", "password", 1, 0, 0)
  23. blnRC = FtpPutFile(lngINetConn, "c:\uploadme.txt", "uploadme.txt", 1, 0)
  24. 'blnRC = FtpGetFile(lngINetConn, "downloadme.txt", "c:\downloadme.txt", 0, 0, 1, 0)
  25.  
  26. InternetCloseHandle lngINetConn
  27. InternetCloseHandle lngINet
  28.  
  29. 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!
Apr 17 '08 #1
2 1511
debasisdas
8,127 Expert 4TB
Which part of the code freezes tha application . Upload or Download ?
Apr 17 '08 #2
I'm sorry, I figured it out FINALLY! This took me forever to get going. The code is below:
Expand|Select|Wrap|Line Numbers
  1. Const scUserAgent = "vb wininet"
  2. Const INTERNET_SERVICE_FTP = 1
  3. Const INTERNET_OPEN_TYPE_DIRECT = 1
  4. Const INTERNET_FLAG_PASSIVE = &H8000000
  5. Const FTP_TRANSFER_TYPE_BINARY = 0
  6. Const FILE_ATTRIBUTE_ARCHIVE = &H20
  7. 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
  8. 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
  9. 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
  10. 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
  11. Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
  12.  
  13.  
  14. Dim hOpen&, hConn&
  15. Dim lRes As Long
  16. hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
  17. hConn = InternetConnect(hOpen, "ftp.thelwcf.com", "21", "username", "password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
  18. lRes = FtpPutFile(hConn, "localfile", "remotefile", FTP_TRANSFER_TYPE_BINARY, 0&)
  19. InternetCloseHandle hConn
  20. InternetCloseHandle hOpen
  21.  
  22. Dim hOpen&, hConn&
  23. Dim lRes As Long
  24. hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
  25. hConn = InternetConnect(hOpen, "ftp.thelwcf.com", "21", "username", "password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
  26. lRes = FtpGetFile(hConn, "remotefile", "localfile", False, FILE_ATTRIBUTE_ARCHIVE, FTP_TRANSFER_TYPE_BINARY, 0&)
  27. InternetCloseHandle hConn
  28. InternetCloseHandle hOpen
  29.  
I guess my constants were off. It's working fast and perfectly now. Thanks anyway!
Apr 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
4
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...
18
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...
4
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...
13
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...
4
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...
21
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...
6
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.