Results 1 to 2 of 2

Thread: File Transfer Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    1

    File Transfer Help

    Im working on file transfer between client and server. This is the data arrival code on the server end:
    vb Code:
    1. Private Const chunk = 4096
    2. Dim numfile As Integer
    3.  
    4. Private Sub Socket2_OnDataArrival(ByVal bytesTotal As Long)
    5.  
    6. Dim NData() As String
    7. Dim data As String
    8.  
    9. Socket2.GetData data
    10.  
    11. NData = Split(data, "|")
    12.  
    13.  
    14. Select Case NData(0)
    15.  
    16. Case "<GH>"
    17. numfile = FreeFile
    18. Open (Dir1.Path & "\" & NData(1)) For Binary As #numfile
    19. filecont = Input(chunk, #numfile)
    20. Socket2.SendData filecont
    21.  
    22. Case "<NP>"
    23. If EOF(numfile) = True Then
    24. Close #numfile
    25. Socket2.SendData "<EF>"
    26. Else
    27. filecont = Input(chunk, #numfile)
    28. Socket2.SendData filecont
    29. End If
    30. End Select
    31. End Sub
    32.  
    33. 'And here is the code for the data arrival on the client side:
    34.  
    35. Private Sub Socket2_OnDataArrival(ByVal bytesTotal As Long)
    36. Dim NData() As String
    37.  
    38. Dim data As String
    39.  
    40. Socket2.GetData data
    41.  
    42. NData = Split(data, "|")
    43.  
    44. Select Case NData(0)
    45.  
    46. Case "<FD>"
    47. Dim fname As String
    48. fname = NData(1)
    49.  
    50. Const ATTR_DIRECTORY = 16
    51. If Dir$(App.Path & "\" & "Downloads", ATTR_DIRECTORY) = "" Then
    52. MkDir (App.Path & "\" & "Downloads")
    53. End If
    54.  
    55. Open (App.Path & "\Downloads\" & fname) For Binary As #1
    56. Socket2.SendData ("<GH>|") & NData(1)
    57.  
    58. Case "<EF>"
    59. Close #1
    60. Socket2.CloseSocket
    61.  
    62. Text1.Text = Text1.Text & vbCrLf & "File Downloaded"
    63.  
    64. Case Else
    65. Put #1, , data
    66.  
    67. DoEvents
    68. Socket2.SendData "<NP>"
    69. End Select
    70. End Sub
    Where I am getting the error is on the server side. Locally when I run both the client and server and transfer files it works just fine, but if I send the server to a buddy and we try a file transfer he always gets the error "Run-time error '52': bad file name or number". Instead of using numfile I have simply tried numbers (#1, #2) but he still gets the same error. I dont understand why it would work locally but not over the internet. I have taken out " Close #numfile " completely and obviously didn't receive an error. Anyone have any ideas? Any help would be greatly appreciated! thank you
    Last edited by Hack; Nov 21st, 2007 at 08:13 AM. Reason: Added Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: File Transfer Help

    Welcome to the forums.

    I edited your post and added [highlight=vb]your code goes in here[/highlight] tags to make the code easier to read.

    My first question whenever an issue like this arises is does your friend have the proper permissions to run against the internet server?

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