Results 1 to 14 of 14

Thread: [RESOLVED] Help With File Transfer Again Please..

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Resolved [RESOLVED] Help With File Transfer Again Please..

    Ok well i got most of it sorted out but i got a new problem an i can't seem to fix it if anyone has time can you optimize my code? the problem i'm having is when i send a file from computer A to computer B , Computer B trys to saves as computer A's directory EG computer A say C:\documents\usernamex\desktop while computer B c:\documents\diffusernamek\desktop so when i send a file to b from a it trys saving as a's directory but it doesnt exist becuase its on a an vice versa?

    Code:
    Private Sub senddataa(sFile As String, sSaveAs As String, tcpCtl As Winsock)
    On Error GoTo ErrHandler
        Dim sSend As String, sBuf As String
        Dim ifreefile As Integer
        Dim lRead As Long, lLen As Long, lThisRead As Long, lLastRead As Long
        
        ifreefile = FreeFile
        
        ' Open file for binary access:
        Open sFile For Binary As #ifreefile
        lLen = LOF(ifreefile)
        
        ' Loop through the file, loading it up in chunks of 64k:
        Do While lRead < lLen
            lThisRead = 65536
            If lThisRead + lRead > lLen Then
                lThisRead = lLen - lRead
            End If
            If Not lThisRead = lLastRead Then
                sBuf = Space$(lThisRead)
            End If
            Get #ifreefile, , sBuf
            lRead = lRead + lThisRead
            sSend = sSend & sBuf
        Loop
        lTotal = lLen
        Close ifreefile
        bSendingFile = True
        '// Send the file notification
        tcpCtl.senddata "FILE" & sSaveAs
        DoEvents
        '// Send the file
        tcpCtl.senddata sSend
        DoEvents
        '// Finished
        tcpCtl.senddata "FILEEND"
        bSendingFile = False
        Exit Sub
    ErrHandler:
        MsgBox "Err " & Err & " : " & Error
    End Sub
    Code:
    Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
        Dim strData As String
        Dim ifreefile
    
        Winsock2.getdata strData
        If Right$(strData, 7) = "FILEEND" Then
            bFileArriving = False
            sArriving = sArriving & Left$(strData, Len(strData) - 7)
            ifreefile = FreeFile
                Open sFile For Binary As #ifreefile
                Put #ifreefile, 1, sArriving
                Close #ifreefile
            lblProgress = "File Transfer Complete"
        ElseIf Left$(strData, 4) = "FILE" Then
            bFileArriving = True
            sFile = Right$(strData, Len(strData) - 4)
        ElseIf bFileArriving Then
            lblProgress = "Receiving " & bytesTotal & " Bytes For " & sFile & " From " & Winsock1.RemoteHostIP
            Label5.Caption = "Connected"
            sArriving = sArriving & strData
        End If
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
        Dim strData As String
        Dim ifreefile
    
        Winsock1.getdata strData
        If Right$(strData, 7) = "FILEEND" Then
            bFileArriving = False
            sArriving = sArriving & Left$(strData, Len(strData) - 7)
            ifreefile = FreeFile
                Open sFile For Binary As #ifreefile
                Put #ifreefile, 1, sArriving
                Close #ifreefile
            lblProgress = "File Transfer Complete"
        ElseIf Left$(strData, 4) = "FILE" Then
            bFileArriving = True
            sFile = Right$(strData, Len(strData) - 4)
        ElseIf bFileArriving Then
            lblProgress = "Receiving " & bytesTotal & " Bytes For " & sFile & " From " & Winsock1.RemoteHostIP
            sArriving = sArriving & strData
        End If
    
    End Sub
    Code:
    Private Sub Command4_Click()
        If Dir$(txtFile) = "" Then
            MsgBox "File Does Not Exist"
        Else
            senddataa txtFile, GetFileName(txtFile), Winsock1
        End If
    End Sub
    
    Private Sub Command5_Click()
        If Dir$(txtFile) = "" Then
            MsgBox "File Does Not Exist"
        Else
            senddataa txtFile, GetFileName(txtFile), Winsock2
        End If
    End Sub
    Code:
    Public Function GetFileName(flname As String) As String
    Dim posn As Integer, i As Integer
    Dim fName As String
        
    posn = 0
    For i = 1 To Len(flname)
    If (Mid(flname, i, 1) = "\") Then posn = i
    Next i
    fName = Right(flname, Len(flname) - posn)
    GetFileName = fName
    End Function
    I make command 4 visible when its the listener or host an command5 hidden vice versa if they connected other way can anyone help
    Last edited by Evilribbet; Jan 8th, 2009 at 02:00 PM.

  2. #2
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    You will have to create the remote folder if it does not exist:
    Dim lDestFolder As String
    Dim diffusername As String

    diffusername = "YourRemoteUserName"
    lDestFolder = "c:\documents and settings\" & diffusername & "\desktop\MyFolder"

    If Dir$(lDestFolder, vbDirectory) = "" Then
    MkDir lDestFolder
    End If
    Exit Sub
    Be sure diffusername is correct
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help With File Transfer Again Please..

    That's the thing though i just want the file to save where the program application is it does do that but it somehow sends one computers directory to the other to save the file which the directory is non existent because it sends its own computers directory to save on other computer but ugh idk im confused

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    Quote Originally Posted by Evilribbet
    That's the thing though i just want the file to save where the program application is it does do that but it somehow sends one computers directory to the other to save the file which the directory is non existent because it sends its own computers directory to save on other computer but ugh idk im confused
    So your saying it does not send just the file, it also sends the path to the file on the sending machine ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help With File Transfer Again Please..

    Yea like it sends but it doesnt send all of the file now, and like say this app is located on your desktop eg c:\documents and settings\johndoe\desktop and the other computer is c:\documents and settings\janedoe\desktop so if you send a file to janedoe from johndoe janedoe trys to save it as johndoe's path and vice versa if you want to take a look ill attach its no big secret xP

    if you have time to look an help id be so grateful
    Last edited by Evilribbet; Jan 8th, 2009 at 07:11 PM.

  6. #6
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    Quote Originally Posted by Evilribbet
    Yea like it sends but it doesnt send all of the file now, and like say this app is located on your desktop eg c:\documents and settings\johndoe\desktop and the other computer is c:\documents and settings\janedoe\desktop so if you send a file to janedoe from johndoe janedoe trys to save it as johndoe's path and vice versa if you want to take a look ill attach its no big secret xP

    if you have time to look an help id be so grateful
    Ity looks to me you are just sending a string with no reference to a file:
    Code:
    Private Sub Command2_Click()
    Dim sName As String
    Dim sData As String
    
    If sckconnect.State = sckConnected Or scklisten.State = sckConnected Then
    sName = ReadRegKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
    sData = sName & "..::.." & Text2.Text
    
    Text1.Text = Text1.Text & sName & "..::.." & Text2.Text & vbNewLine
    
    sckconnect.senddata sData
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help With File Transfer Again Please..

    Lul forgot to mention im using multiple winsock controls, that peice of code is just for the chat, Winsock1 And Winsock2 is the file transfers and senddata/getdata are used for the screenshot video preview

  8. #8
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    Quote Originally Posted by Evilribbet
    Lul forgot to mention im using multiple winsock controls, that peice of code is just for the chat, Winsock1 And Winsock2 is the file transfers and senddata/getdata are used for the screenshot video preview
    You might need help from someone who knows about Winsock. Seems something is missing to me. It looks like the destination path has the where and text combined (sData). Never tried what you are doing. I will be interested to see how this comes out. To be sure i am understanding you want to write text messages on a remote desktop with no file involved?
    Someone here will probably have a solutation.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help With File Transfer Again Please..

    Okay well im basically makeing a remote desktop helper i got the idea cuz my dad keeps getting viruses and this way he'll be able to direct connect with me if he needs help as well as if others want it too the breakdown

    1. Chat-You will be able to chat while connected back and forth
    2. File Transfer-Send files back and forth
    3. Preview of there desktop (host only)

    all of these i am using in this program as one single desktop helper so they all connect at the same time thats why i have multiple winsock controls everything works except the file transfer giving me a headache, so basically everything connects at same time so you can chat,transfer files and preview there desktop , just having trouble with the file transfer xP but if anyone else would like to help you welcome too it thanks though for peeking at it

  10. #10
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    Quote Originally Posted by Evilribbet
    Okay well im basically makeing a remote desktop helper i got the idea cuz my dad keeps getting viruses and this way he'll be able to direct connect with me if he needs help as well as if others want it too the breakdown

    1. Chat-You will be able to chat while connected back and forth
    2. File Transfer-Send files back and forth
    3. Preview of there desktop (host only)

    all of these i am using in this program as one single desktop helper so they all connect at the same time thats why i have multiple winsock controls everything works except the file transfer giving me a headache, so basically everything connects at same time so you can chat,transfer files and preview there desktop , just having trouble with the file transfer xP but if anyone else would like to help you welcome too it thanks though for peeking at it
    I was checking into something similar a while back to make a live help for my website., but could not get past the ports and Ip parts, I finally settled on a free one http://www.livezilla.net/downloads/ and gotta say it sure works good for free.
    Of course who knows free for how long. It has all the things you specified except the ability to view a remote desktop. I hope someone helps you as I may need the answer down the road myself. This site has some very sharp coders. If nobody helps in the next day I will post the same question if you don't mind
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help With File Transfer Again Please..

    I think ive found the problem im gonna do more testing an keep you updated

  12. #12
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    Quote Originally Posted by Evilribbet
    I think ive found the problem im gonna do more testing an keep you updated
    I'm glad Thank you
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help With File Transfer Again Please..

    Hey yo, alright i seemed to have to fixed it pretty damn good if i say so myself, bunch errors on top errors but got em all heres a list for future references

    1. Like before never put DoEvents in a data arrival event i've learned that now
    2. I was not specifing a save path for the file when it arrives easily done with a directory box or commondialog control, preferably directory box for me
    3. It wasn't sending the filename and extension properly easily fixed on the data arrival event
    4. On data arrival event for files you must clear the old binary data out of the temp string on send file complete else it would merge with other data thus cause corrupt data

    Lol took me awhile to think the code over but it is working properly , if you would like the source+project let me know this could be as helpful to you as it is me, as i said before it is a remote desktop helper designed for mainly56k and really high connections

  14. #14
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help With File Transfer Again Please..

    Quote Originally Posted by Evilribbet
    Hey yo, alright i seemed to have to fixed it pretty damn good if i say so myself, bunch errors on top errors but got em all heres a list for future references

    1. Like before never put DoEvents in a data arrival event i've learned that now
    2. I was not specifing a save path for the file when it arrives easily done with a directory box or commondialog control, preferably directory box for me
    3. It wasn't sending the filename and extension properly easily fixed on the data arrival event
    4. On data arrival event for files you must clear the old binary data out of the temp string on send file complete else it would merge with other data thus cause corrupt data

    Lol took me awhile to think the code over but it is working properly , if you would like the source+project let me know this could be as helpful to you as it is me, as i said before it is a remote desktop helper designed for mainly56k and really high connections
    Thanks I would like to have the source code, as I will probably be making my own live chat at some point.
    I have had run in's with DoEvents a few times. It has caused me a great deal of problems and other times it was a perfect fix. Just yesterday I was trying to make a form invisible and it fixed my problem:
    Me.Visible = False
    'DoEvents
    Sleep 1800
    Me.Visible = True
    The form would only be partially invisible until I added doevents
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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