Results 1 to 6 of 6

Thread: semi-crash with ftp, no idea why

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    20

    Angry semi-crash with ftp, no idea why

    I've got a strange problem...

    I made a form for resizing a pic and uploading it to a server. Played around with to make sure it fully works, and it does what it's supposed to do for now. But then I restarted my pc, and now when I run the program and it goes into the ftp-part of it, everything still works, but if I close the program it seems to crash for about 20-25sec. If I check my task manager it shows processes of the running exe, and vb6, both "not responding" but after those 25sec (more or less) they both become "running" again and everything goes back to normal.

    Any idea how this can happen?? Nothing changed in the code before or after rebooting the pc. I'm absolutely clueless about it, but it sucks big time of course.

    Here's the code:

    VB Code:
    1. 'Option Explicit
    2.  
    3. Private Declare Function BmpToJpeg Lib "Bmp2Jpeg.dll" ( _
    4. ByVal BmpFilename As String, _
    5. ByVal JpegFilename As String, _
    6. ByVal CompressQuality As Integer) As Integer
    7.  
    8. 'ftp functions via vbforums.com, Joacim Andersson
    9. Private Declare Function FtpGetFile Lib "wininet.dll" _
    10. Alias "FtpGetFileA" ( _
    11. ByVal hFtpSession As Long, _
    12. ByVal lpszRemoteFile As String, _
    13. ByVal lpszNewFile As String, _
    14. ByVal fFailIfExists As Boolean, _
    15. ByVal dwFlagsAndAttributes As Long, _
    16. ByVal dwFlags As Long, _
    17. ByVal dwContext As Long) As Boolean
    18.  
    19. Private Declare Function FtpPutFile Lib "wininet.dll" _
    20. Alias "FtpPutFileA" ( _
    21. ByVal hFtpSession As Long, _
    22. ByVal lpszLocalFile As String, _
    23. ByVal lpszRemoteFile As String, _
    24. ByVal dwFlags As Long, _
    25. ByVal dwContext As Long) As Boolean
    26.  
    27. Private Declare Function InternetOpen Lib "wininet.dll" _
    28. Alias "InternetOpenA" ( _
    29. ByVal sAgent As String, _
    30. ByVal nAccessType As Long, _
    31. ByVal sProxyName As String, _
    32. ByVal sProxyByPass As String, _
    33. ByVal nFlags As Long) As Long
    34.  
    35. Private Declare Function InternetConnect Lib "wininet.dll" _
    36. Alias "InternetConnectA" ( _
    37. ByVal hInternetSession As Long, _
    38. ByVal sServerName As String, _
    39. ByVal nServerPort As Integer, _
    40. ByVal sUserName As String, _
    41. ByVal sPassword As String, _
    42. ByVal nService As Long, _
    43. ByVal dwFlags As Long, _
    44. ByVal dwContext As Long) As Long
    45.  
    46. Private Declare Function FtpCreateDirectory _
    47.  Lib "wininet.dll" Alias "FtpCreateDirectoryA" ( _
    48.  ByVal hFtpSession As Long, _
    49.  ByVal lpszDirectoryName As String) As Boolean
    50.  
    51. Private Declare Function FtpSetCurrentDirectory _
    52.  Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" ( _
    53.  ByVal hFtpSession As Long, _
    54.  ByVal lpszDirectoryName As String) As Boolean
    55.  
    56. Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
    57. ByVal hInet As Long) As Integer
    58.  
    59. Private Const INTERNET_SERVICE_FTP = 1
    60. Private Const INTERNET_SERVICE_GOPHER = 2
    61. Private Const INTERNET_SERVICE_HTTP = 3
    62.  
    63. Public Sub resizePic()
    64. Dim filename, picpath, reverse As String
    65. Dim start, i As Integer
    66. Picture1.Picture = LoadPicture()
    67. Picture2.Picture = LoadPicture()
    68.  
    69. reverse = ""
    70. For i = 1 To Len(frmSwitchboard.rsProperty.Fields("pr_pic").Value)
    71.         reverse = reverse & Mid(frmSwitchboard.rsProperty.Fields("pr_pic").Value, Len(frmSwitchboard.rsProperty.Fields("pr_pic").Value) - i + 1, 1)
    72. Next
    73. start = InStr(1, reverse, "\")
    74. 'picpath = Mid(rsProperty.Fields("pr_pic"), 1, Len(rsProperty.Fields("pr_pic")) - start)
    75. filename = Mid(frmSwitchboard.rsProperty.Fields("pr_pic"), Len(frmSwitchboard.rsProperty.Fields("pr_pic")) - start + 2, start - 5)
    76. 'filename = Left(dlg.filename, Len(dlg.filename) - 4)
    77. Picture1.Picture = LoadPicture(frmSwitchboard.rsProperty.Fields("pr_pic"))
    78. 'Resizing
    79.  
    80. Picture2.AutoRedraw = True
    81. 'Picture2.Width = 400
    82. 'Picture2.Height = 300
    83. Picture2.PaintPicture Picture1.Picture, _
    84. Picture2.ScaleLeft, Picture2.ScaleTop, _
    85. Picture2.ScaleWidth, Picture2.ScaleHeight, _
    86. Picture1.ScaleLeft, Picture1.ScaleTop
    87. Picture2.Picture = Picture2.Image
    88.  
    89. 'Saving the file as Bitmap
    90. SavePicture Picture2.Picture, "C:\" & filename & ".bmp"
    91. 'For saving into jpg format you must have
    92. 'the Bmp2Jpeg.dll file in your windows folder
    93. 'Change the bitmap file to the jpg file with the Bmp2Jpg.dll
    94. '60 is the Compress Quality
    95. BmpToJpeg "C:\" & filename & ".bmp", "C:\" & filename & ".jpg", 60
    96. 'Deleting the bitmap file
    97. Kill "C:\" & filename & ".bmp"
    98. uploadPic frmSwitchboard.rsProperty.Fields("pr_code").Value, "C:\", filename & ".jpg"
    99. Kill "C:\" & filename & ".jpg"
    100. End Sub
    101.  
    102. Public Sub uploadPic(dirName As String, filePath As String, file As String)
    103. 'dirName = name of target folder on server
    104. 'filePath is e.g. "C:\"
    105. 'file full name of the file, e.g. "picture.jpg"
    106. 'Dim hINetSession As Variant
    107. 'Dim hsession As Variant
    108. retry:
    109. hINetSession = InternetOpen("testftp", 0, vbNullString, vbNullString, 0)
    110. hsession = InternetConnect(hINetSession, "127.0.0.1", "21", "test", "test", INTERNET_SERVICE_FTP, 0, 0)
    111.  
    112. If FtpSetCurrentDirectory(hsession, dirName) = False Then
    113.     FtpCreateDirectory hsession, dirName
    114. End If
    115. FtpSetCurrentDirectory hsession, dirName
    116.     If FtpPutFile(hsession, filePath & file, file, 1, 0) = False Then
    117.         If MsgBox("Error occurred. Code: " & Err.LastDllError & vbCrLf & "Retry?", vbYesNo + vbQuestion) = vbYes Then
    118.             GoTo retry:
    119.         Else
    120.             MsgBox ("Upload failed.")
    121.             Exit Sub
    122.         End If
    123.     Else
    124.         MsgBox "upload success"
    125.     End If
    126. Call InternetCloseHandle(hsession)
    127. Call InternetCloseHandle(hINetSession)
    128. End Sub

    to start it I just attached it to a menu item in my main form.
    so that on click it goes "frmFTP.resizePic"

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: semi-crash with ftp, no idea why

    Only bit I can see there is that if it errors it will reopen an internet connections and ftp connection, without closing the previous ones.

    Might be something there?
    Instead of looping back, display an error msg and exit closing off and see if the problem still occurs.

    Secondly. remark out all the ftp part and see if it still works fine, then add in the internet connection and the ftp connection.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    20

    Re: semi-crash with ftp, no idea why

    i made sure it can't make errors, at least not for now.

    if i remark out all the ftp, it closes completely normal. the thing that puzzles me most is that is just started happening after the reboot, not a single letter in the code changed, I just start the project again and ran it.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    20

    Re: semi-crash with ftp, no idea why

    i experimented some more with it today... It's real strange, when I run through it step bt step in debug it closes fine from then on (that was yesterday). Today I tried working some more, and it freezed again. Did the same thing, run through it line by line with debug... then closed: no problem. So at this moment it's running good, but for how long??

    Also, shouldn't the internetclosehandle set the hsession to 0 or Null? Because after I call it, it's still a "long" value. What does the closehandle do exactly then?

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: semi-crash with ftp, no idea why

    It leaves the handle, all it does is tell the system that it has to close that handle. If the returned value on the call is 1 its gone. If its 0 it has errored. And you should be able to see the last dll error to decide what the problem was.

    Stepping through works fine, but running doesn't?

    Might be a declaration wrong or that you aren't giving the comp time to process something.
    Perhaps shove a doevents in the loop?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    20

    Re: semi-crash with ftp, no idea why

    sorry, what do you mean by do events in the loop?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width