473,395 Members | 1,622 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,395 software developers and data experts.

uploading and down loading files

15
Hi
I Need Help For Uploading And Down Loading Files Using Internet Tansfer Control. When Assign The Name Of File In A Variable, It Does Not Execute The State Change Event. When I Give The File Name Directly It Execute The State Change Event And Down Load And Uploadin Process Success.

My Requirement Is To Down Load Selected Files From A List Of Server Files

Very Urgent
Oct 5 '06 #1
3 3412
sashi
1,754 Expert 1GB
Hi there,

Can you pls show your code segment on your next post, i feel it's alot more easier to troubleshoot, take care my fren.. :)
Oct 5 '06 #2
mra
15
thank you
this is my code
'**********************
Expand|Select|Wrap|Line Numbers
  1. Dim CnTest As New ADODB.Connection
  2. Dim i As Integer
  3. Dim ConnectedFlag As Boolean
  4. Dim ServerDirFlag As Boolean
  5. Dim DownloadFlag As Boolean
  6. Dim UploadFlag As Boolean
  7. Dim FileSizeFlag As Boolean
  8. Dim homeLen As Integer
  9. Dim LocFilespec As String
  10. Dim SerFilespec As String
  11. Dim gFileSize As String
  12. Private Sub cmdConnect_Click()
  13. Dim tmp As String
  14. Dim i As Integer
  15. Dim tmpPath As String
  16. Dim tmpFile As String
  17. Dim bExist As Boolean
  18. Dim lFileSize As Long
  19. ConnectedFlag = False
  20. ClearFlags
  21. lblStatus.Caption = "To connect ...."
  22. With Inet1
  23.  .AccessType = icDirect
  24.  .RequestTimeout = 0
  25.   .URL = "ftp://urlname"
  26. .UserName = "username"
  27.  .Password = "password"
  28. End With
  29. If RptFlag = 9 Then
  30. ServerDirFlag = True
  31. Inet1.Execute , "DIR wwwroot/*.mdb"
  32. Do While Inet1.StillExecuting
  33. DoEvents
  34. Loop
  35. End If
  36. If IsNetConnected() Then
  37. ConnectedFlag = True
  38. UpdButtons
  39. Else
  40. GoTo errHandler
  41. End If
  42. Exit Sub
  43. errHandler:
  44. End Sub
  45. Private Sub cmdDisconnect_Click()
  46. On Error Resume Next
  47. Inet1.Cancel
  48. Inet1.Execute , "CLOSE"
  49. lblStatus.Caption = "Unconnected"
  50. ConnectedFlag = False
  51. lisServerFiles.Clear
  52. ClearFlags
  53. UpdButtons
  54. End Sub
  55. Private Sub CmdDownLoad_Click()
  56. If ConnectedFlag = False Then
  57. MsgBox "No connection yet"
  58. Exit Sub
  59. End If
  60. lblStatus.Caption = "Retreiving file..."
  61. If lisServerFiles.SelCount > 1 Then
  62. MsgBox "INVALID SELECTION,PLEASE SELECT SINGLE FILE FOR DOWNLOADING AT A TIME", vbInformation, Me.Caption
  63. Exit Sub
  64. ElseIf lisServerFiles.SelCount = 1 Then
  65. SerFilespec = " ftp://urlname.com/wwwroot/" & lisServerFiles.List(i)
  66. Else
  67. MsgBox "INVALID SELECTION,PLEASE SELECT A FILE U WANT TO DOWNLOAD", vbInformation, Me.Caption
  68. Exit Sub
  69. End If
  70. LocFilespec = SerFilespec
  71. Do While InStr(LocFilespec, "/") <> 0
  72. LocFilespec = Right(LocFilespec, Len(LocFilespec) - _
  73. InStr(LocFilespec, "/"))
  74. Loop
  75. If IsFileThere(LocFilespec) Then
  76. If MsgBox(LocFilespec & " already exist. Overwrite?", _
  77. vbYesNo + vbQuestion) = vbNo Then
  78. Else
  79. Kill LocFilespec
  80. End If
  81. End If
  82. lblStatus.Caption = "Requesting for file size..."
  83. gFileSize = ""
  84. SerFilespec = " wwwroot/FACTORY1.MDB"
  85. LocFilespec = "C:\CASHEWORIG\PRODUCTION\FACTORY1.mdb"
  86. DownloadFlag = True
  87. Inet1.Execute "GET " & SerFilespec & LocFilespec
  88. '     Inet1.Execute , "GET wwwroot/FACTORY1.mdb C:\CASHEWORIG\PRODUCTION\FACTORY1.mdb"
  89. '     Inet1.Execute , "GET wwwroot/" & lisServerFiles.List(i) & App.Path & "\" & lisServerFiles.List(i)
  90. '     Inet1.Execute , "Get " & SerFilespec & LocFilespec
  91. Do While Inet1.StillExecuting
  92. DoEvents
  93. If ConnectedFlag = False Then
  94. Exit Sub
  95. End If
  96. Loop
  97. lblStatus.Caption = "Connected"
  98. Exit Sub
  99. End Sub
  100. Private Sub CmdUpLink_Click()
  101. On Error Resume Next
  102. If ConnectedFlag = False Then
  103. MsgBox "No connection yet"
  104. Exit Sub
  105. End If
  106. LocFilespec = App.Path & "\CSTOCK.MDB"
  107. lFileSize = FileLen(LocFilespec)
  108. lblStatus.Caption = "Uploading file..."
  109. UploadFlag = True
  110. Inet1.Execute , "PUT " & App.Path & "\CSTOCK.MDB" & " wwwroot/CSTOCK.MDB"
  111. Do While Inet1.StillExecuting
  112. DoEvents
  113. If ConnectedFlag = False Then
  114. Exit Sub
  115. End If
  116. Loop
  117. lblStatus.Caption = "Connected"
  118. Exit Sub
  119. errHandler:
  120. If icExecuting Then
  121. If ConnectedFlag = False Then
  122. Exit Sub
  123. End If
  124. If MsgBox("Executing job. Cancel it?", vbYesNo + vbQuestion) = vbYes Then
  125. Inet1.Cancel
  126. If Inet1.StillExecuting Then
  127. lblStatus.Caption = "System failed to cancel job"
  128. End If
  129. Else
  130. Resume
  131. End If
  132. End If
  133. 'ErrMsgProc "cmdConnect_Click"
  134. End Sub
  135. Sub ErrMsgProc(mMsg As String)
  136. MsgBox mMsg & vbCrLf & Err.Number & Space(5) & Err.Description
  137. End Sub
  138. Private Sub Form_Load()
  139. ConnectedFlag = False
  140. ClearFlags
  141. Select Case RptFlag
  142. Case 9  ' DOWN LOAD
  143. Me.Caption = "DOWN LOAD"
  144. CmdDownLoad.Enabled = True
  145. CmdDownLoad.Visible = True
  146. CmdUpLink.Enabled = False
  147. CmdUpLink.Visible = False
  148. lisServerFiles.Visible = True
  149. Case 10 ' UPLINK
  150. Me.Caption = "UPLOAD"
  151. CmdDownLoad.Enabled = False
  152. CmdDownLoad.Visible = False
  153. CmdUpLink.Enabled = False
  154. CmdUpLink.Visible = True
  155. lisServerFiles.Visible = False
  156. End Select
  157. 'DIR_OBJ
  158. UpdButtons
  159. End Sub
  160. Private Sub Form_Unload(Cancel As Integer)
  161. On Error Resume Next
  162. Inet1.Execute , "CLOSE"
  163. Unload Me
  164. End Sub
  165. Private Sub Inet1_StateChanged(ByVal State As Integer)
  166. On Error Resume Next
  167. Select Case State
  168. Case icError                                      ' 11
  169. lblStatus = Inet1.ResponseCode & ": " & Inet1.ResponseInfo
  170. Inet1.Execute , "CLOSE"
  171. lisServerFiles.Clear
  172. ConnectedFlag = False
  173. ServerDirFlag = False
  174. DownloadFlag = False
  175. UpdButtons
  176. Case icResponseCompleted                          ' 12
  177. Dim bDone As Boolean
  178. Dim tmpData As Variant
  179. If ServerDirFlag = True Then
  180. Dim dirData As String
  181. Dim strEntry As String
  182. Dim i As Integer, k As Integer
  183. tmpData = Inet1.GetChunk(4096, icString)
  184. dirData = dirData & tmpData
  185. If dirData <> "" Then
  186. lisServerFiles.Clear
  187.  For i = 1 To Len(dirData) - 1
  188. k = InStr(i, dirData, vbCrLf)
  189. strEntry = Mid(dirData, i, k - i)
  190. If Right(strEntry, 1) = "/" Then
  191.  strEntry = Left(strEntry, Len(strEntry) - 1) & "/"
  192. End If
  193. If Trim(strEntry) <> "" Then
  194.  lisServerFiles.AddItem strEntry
  195. End If
  196. i = k + 1
  197. DoEvents
  198. Next i
  199. lisServerFiles.ListIndex = 0
  200. End If
  201. ServerDirFlag = False
  202. lblStatus.Caption = "Dir completed"
  203. ElseIf DownloadFlag Then
  204. Dim varData As Variant
  205. bDone = False
  206. Open LocFilespec For Binary Access Write As #1
  207. ' Get first chunk
  208.  tmpData = Inet1.GetChunk(10240, icByteArray)
  209.                  DoEvents
  210.                  If Len(tmpData) = 0 Then
  211.                       bDone = True
  212.                  End If
  213.                  Do While Not bDone
  214.                       varData = tmpData
  215.                       Put #1, , varData
  216.                       tmpData = Inet1.GetChunk(10240, icByteArray)
  217.                       DoEvents
  218.                       If ConnectedFlag = False Then
  219.                            Exit Sub
  220.                       End If
  221.                       If Len(tmpData) = 0 Then
  222.                             bDone = True
  223.                       End If
  224.                  Loop
  225.                  Close #1
  226.                  DownloadFlag = False
  227.                  DoEvents
  228.                  lblStatus.Caption = "Download completed"
  229.                  DownloadFlag = False
  230.                  MsgBox "Download completed:" & vbCrLf & vbCrLf & _
  231.                      "File in current dir, named  " & LocFilespec
  232.              ElseIf UploadFlag Then
  233.                  lblStatus.Caption = "Connected"
  234.                  UploadFlag = False
  235.                  MsgBox "Upload completed"
  236.               ElseIf FileSizeFlag Then
  237.                  Dim sizeData As String           
  238.                  tmpData = Inet1.GetChunk(1024, icString)
  239.                  DoEvents
  240.                  If Len(tmpData) > 0 Then
  241.                       sizeData = sizeData & tmpData
  242.                  End If
  243.                   gFileSize = sizeData
  244.                  FileSizeFlag = False
  245.               Else
  246.                  lblStatus.Caption = "Connected"
  247.             End If
  248.         Case icNone                                       ' 0
  249.             lblStatus.Caption = "No state to report"
  250.         Case icResolvingHost                              ' 1
  251.             lblStatus.Caption = "Resolving host..."
  252.         Case icHostResolved                               ' 2
  253.             lblStatus.Caption = "Host resolved - found its IP address"
  254.         Case icConnecting                                 ' 3
  255.             lblStatus.Caption = "Connecting..."
  256.         Case icConnected                                  ' 4
  257.             lblStatus.Caption = "Connected"
  258.         Case icRequesting                                 ' 5
  259.             lblStatus.Caption = "Sending requesst..."
  260.         Case icRequestSent                                ' 6
  261.             lblStatus.Caption = "Request sent"
  262.         Case icReceivingResponse                          ' 7
  263.             lblStatus = "Receiving data..."
  264.         Case icResponseReceived                           ' 8
  265.             lblStatus = "Response received"
  266.         Case icDisconnecting                              ' 9
  267.             lblStatus.Caption = "Disconnecting..."
  268.         Case icDisconnected                               '10
  269.             lblStatus = "Disconnected"
  270.     End Select
  271. End Sub
  272. Private Sub ClearFlags()
  273.     ServerDirFlag = False
  274.     DownloadFlag = False
  275.     UploadFlag = False
  276.     FileSizeFlag = False
  277. End Sub
  278. Private Sub UpdButtons()
  279.     cmdConnect.Enabled = False
  280.     CmdDownLoad.Enabled = False
  281.     CmdUpLink.Enabled = False
  282.     cmdDisconnect.Enabled = False
  283.     If ConnectedFlag Then
  284.          CmdDownLoad.Enabled = True
  285.          cmdDisconnect.Enabled = True
  286.     Else
  287.          cmdConnect.Enabled = True
  288.     End If
  289. End Sub
  290. '*********************************************************
  291. 'MODULE
  292. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags _
  293.       As Long, ByVal dwReserved As Long) As Long
  294. Public RptFlag As Integer
  295. Function IsNetConnected() As Boolean
  296.     IsNetConnected = InternetGetConnectedState(0, 0)
  297. End Function
  298. Function IsFileThere(inFileSpec As String) As Boolean
  299.     On Error Resume Next
  300.     Dim i
  301.     i = FreeFile
  302.     Open inFileSpec For Input As i
  303.     If Err Then
  304.         IsFileThere = False
  305.     Else
  306.         Close i
  307.         IsFileThere = True
  308.     End If
  309. End Function
  310.  
Please give me a solution
Oct 9 '06 #3
mra
15
Hi there,

Can you pls show your code segment on your next post, i feel it's alot more easier to troubleshoot, take care my fren.. :)
I GOT IT IT IS A SIMPLE MISTAKE Lack OF A COMMA
Oct 9 '06 #4

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

Similar topics

4
by: dickiedyce | last post by:
Hi there. I've spent the weekend getting ever more frustrated, trying to get an upload file function working on a website. The site is hosted by a company called oneandone. They're using PHP...
5
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
3
by: Kamen TOMOV | last post by:
Hi, Is uploading recursively directories to a web server possible with JavaScript? I mean is it possible read a directory recursively and dynamically construct <input type="file"> with value...
4
by: muthu | last post by:
Hi, User will upload only picture and pdf files. I have return a asp.net application for that,But thing is I need to restrict the user uploading corrupted or damaged files. Can anyone have any...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
2
by: matech | last post by:
I have a problem with uploading special characters from excel files to mysql 5. It doesn't matter if I use UTF-8 or iso-8859-1 when uploading the trademark ™ symbol. htmlspecialchars() or...
1
by: =?Utf-8?B?RGFu?= | last post by:
MS won't seem to let me reply to my old post, so I created a new one. The error occurs in all browsers. It's definitely a server issue, not client. The server is not proxied in any way. I tried...
3
by: muziburrehaman | last post by:
i am looking for code in php to upload the 1 gb files. any one can please help me by sending the code....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.