Sign in to follow this  
Followers 0
FireFox

[RESOLVED] Send File to other computer with IP

3 posts in this topic

#1 ·  Posted (edited)

Hi,

I want to make my file transfert working, I havn't lot of friends that can help me for this kind of script...

;~ #include <_GetIP.au3>
#include <INet.au3>

Opt('GuiOnEventMode', 1)
$LIP = @IPAddress1
$IP = _GetIP()

#Region GUI
$GUI = GUICreate('SF <d3montools>', 300, 150, -1, -1, -1, BitOR(0x00040000, 0x00000080, 0x00000010))
GUISetOnEvent(-3, '_Exit')
GUISetOnEvent(-13, '_DROP')

GUICtrlCreateTab(5, 5, 290, 140)
GUICtrlCreateTabItem('SEND')
$FILE = GUICtrlCreateEdit('Drag a file to send or click on browse button >>', 15, 35, 240, 20, 2048 + 128)
GUICtrlSetState(-1, 8)

GUICtrlCreateButton('...', 262, 35, 23, 20)
GUICtrlSetOnEvent(-1, '_BIN')
$CIP = GUICtrlCreateCombo($IP & ':21', 15, 62, 130, 20, 0x3)
GUICtrlCreateButton('...', 150, 62, 23, 20)
GUICtrlSetOnEvent(-1, '_AddCIP')

GUICtrlCreateButton('SEND !', 185, 62, 100, 20)
GUICtrlSetOnEvent(-1, '_SEND')

GUICtrlCreateTabItem('RECEIVE')
$OUT = GUICtrlCreateEdit(@DesktopDir, 15, 35, 240, 20, 2048)
GUICtrlCreateButton('...', 262, 35, 23, 20)
GUICtrlSetOnEvent(-1, '_BOUT')
$LOCALIP = GUICtrlCreateCombo($LIP & ':21', 15, 62, 130, 20, 0x3)
GUICtrlCreateButton('...', 150, 62, 23, 20)
GUICtrlSetOnEvent(-1, '_AddLIP')

GUICtrlCreateButton('RECEIVE !', 185, 62, 100, 20)
GUICtrlSetOnEvent(-1, '_RECEIVE')
GUISetState(@SW_SHOW, $GUI)
#EndRegion


While 1
    Sleep(250)
WEnd

Func _BIN()
    $ADD = FileOpenDialog('Select file to send', '', 'd3monCorp (*.*)', 1 + 2, '')
    If Not @error Then
        GUICtrlSetData($FILE, $ADD)
    EndIf
EndFunc   ;==>_BIN

Func _DROP()
    GUICtrlSetData($FILE, @GUI_DragFile)
EndFunc   ;==>_DROP

Func _BOUT()
    $ADD = FileSelectFolder('Select output folder for file(s) received', '', 6, @DesktopDir)
    If Not @error Then
        GUICtrlSetData($OUT, $ADD)
    EndIf
EndFunc   ;==>_BOUT

Func _AddCIP()
    $NIP = InputBox('SF - Add IP', 'Enter IP:PORT to add...' & @CRLF & '"DEL" will delete IP:PORT', '000.000.000.000:0000', '', 200, 125)
    If Not @error Then
        If $NIP = 'DEL' Then
            GUICtrlSetData($CIP, '')
            GUICtrlSetData($CIP, $IP & ':21', $IP & ':21')
        Else
            GUICtrlSetData($CIP, $NIP)
        EndIf
    EndIf
EndFunc   ;==>_AddCIP

Func _AddLIP()
    $NIP = InputBox('SF - Add IP', 'Enter IP:PORT to add...' & @CRLF & '"DEL" will delete IP:PORT', '000.000.000.000:0000', '', 200, 125)
    If Not @error Then
        If $NIP = 'DEL' Then
            GUICtrlSetData($LOCALIP, '')
            GUICtrlSetData($LOCALIP, $LIP & ':21', $LIP & ':21')
        Else
            GUICtrlSetData($LOCALIP, $NIP)
        EndIf
    EndIf
EndFunc   ;==>_AddLIP

Func _Exit()
    Exit
EndFunc   ;==>_Exit


Func _SEND()
    $IPPORT = StringSplit(GUICtrlRead($CIP), ':')
    _FileSend(GUICtrlRead($FILE), $IPPORT[1], $IPPORT[2], 1, 1)
EndFunc   ;==>_SEND

Func _RECEIVE()
    $IPPORT = StringSplit(GUICtrlRead($LOCALIP), ':')
    _FileReceive('', $IPPORT[1], $IPPORT[2], 1)
EndFunc   ;==>_RECEIVE


;===============================================================================
;    Function Name:       _FileSend
;    Description:        Sending a File to an Server (See _FileReceive)
;    Parameter(s):        $sFile    : The File to send
;                        $IP        : The target IP Adress
;                        $PORT [Optional]    :     The Port to use (must be the same as by _FileReceive!!)
;                        $iSplash [Optional]    :    1 (default) = show SplashText
;                                                0 = dont show SplashText
;                        $iWaitWhileConnected [Optional] :    0 = If TCPConnect faild (@error) Return with error Code 2
;                                                            1(Default) = If TCPConnect faild put it in a while until connected
;    Requirement(s):     -
;    Return Value(s):    On Succes Return 1
;                        On faild Return -1 and @error code 1-3:
;                        @error = 1: File not exist
;                        @error = 2: TCPConnect faild (only able if $iWaitWhileConnected <> 1)
;                        @error = 3: Faild to Open File
;                         @error = 4: A Connectionproblem while sending
;    Author(s):            GtaSpider
;===============================================================================
Func _FileSend($sFile, $IP, $PORT = 4324, $iSplash = 1, $iWaitWhileConnected = 1)
    Local $iMainSocket = -1, $sBuff, $iFileOp, $sRecv

    If Not FileExists($sFile) Then Return SetError(1, 0, -1)
    If $iSplash Then $iSplash = TrayTip('_FileSend', 'Try to connect...', 1, 1)
    TCPStartup()

    If Number($iWaitWhileConnected) = 1 Then
        While $iMainSocket = -1
            $iMainSocket = TCPConnect($IP, $PORT)
        WEnd
    Else
        $iMainSocket = TCPConnect($IP, $PORT)
        If @error Then Return SetError(2, 0, -1)
    EndIf
    If $iSplash Then TrayTip('_FileSend', 'Read File...', 1, 1)
    $iFileOp = FileOpen($sFile, 16)
    If @error Then Return SetError(3, 0, -1)
    $sBuff = Binary(StringTrimLeft($sFile, StringInStr($sFile, '\', -1, -1)) & ',') & FileRead($iFileOp)
    FileClose($iFileOp)
    If $iSplash Then TrayTip('_FileSend', 'Sending File...', 1, 1)
    While BinaryLen($sBuff)
        $iSendReturn = TCPSend($iMainSocket, $sBuff)
        If @error Then Return SetError(4, 0, -1)
        TrayTip('', $iSendReturn, 1)
        $sBuff = BinaryMid($sBuff, $iSendReturn + 1, BinaryLen($sBuff) - $iSendReturn)
    WEnd
    If $iSplash Then TrayTip('_FileSend', 'Succesfull!', 1, 1)
    TCPCloseSocket($iMainSocket)
    TCPShutdown()
    Sleep(1000)
    SplashOff()
    Return 1
EndFunc   ;==>_FileSend


;===============================================================================
;    Function Name:        _FileReceive
;    Description:        Receives a File from an Client (See _FileSend)
;    Parameter(s):        $sFileName [Optional]    : The Filename to save (if default or '' then using the original File Name)
;                        $IP [Optional]            : The IP where the Server run, Default = @IPAdress1
;                        $PORT [Optional]        : The Port to use (must be the same as by _FileSend!!)
;                        $iSplash [Optional]        : 1 (default) = show SplashText
;    Requirement(s):        -
;    Return Value(s):    On Succes Return 1
;    On faild Return     -1 and @error code 1-3:
;                        @error = 1: Error creating Listening socket on IP
;                        @error = 2: Faild to open file
;                        @error = 3: Faild to write file
;    Author(s):            GtaSpider
;===============================================================================
Func _FileReceive($sFileName = '', $IP = @IPAddress1, $PORT = 4324, $iSplash = 1)
    Local $iMainSocket, $iAccSocket = -1, $sBuff, $sRecv = '', $i = 0, $iFirstWhile = True
    TCPStartup()

    $iMainSocket = TCPListen($IP, $PORT)
    If @error Then Return SetError(1, 0, -1)
    If $iSplash Then $iSplash = TrayTip('_FileReceive', 'Wait For Incoming...', 1, 1)
    While $iAccSocket = -1
        $iAccSocket = TCPAccept($iMainSocket)
        Sleep(50)
    WEnd
    $sBuff = Binary($sBuff)

    If $iSplash Then TrayTip('_FileReceive', 'Incoming...', 1, 1)

    While $sRecv = ''
        $sRecv = TCPRecv($iAccSocket, 2048, 1)
        $sRecv = BinaryToString($sRecv)
    WEnd
    If $iSplash Then TrayTip('_FileReceive', 'Receive File...', 1, 1)
    While $sRecv <> ''
        If StringInStr($sRecv, ',') And $iFirstWhile Then
            $sTmp = StringLeft($sRecv, StringInStr($sRecv, ',') - 1)
            $sRecv = StringTrimLeft($sRecv, StringLen($sTmp) + 1)
            If StringLen($sFileName) < 1 Then $sFileName = $sTmp
            $iFirstWhile = False
        EndIf
        $sBuff &= $sRecv
        $sRecv = BinaryToString(TCPRecv($iAccSocket, 2048, 1))
        If @error Then ExitLoop
    WEnd
    If $iSplash Then TrayTip('_FileReceive', 'Write To File...', 1, 1)
    If FileExists($sFileName) Then
        $sTmp = StringSplit($sFileName, '.')
        If $sTmp[0] < 2 Then
            While 1
                $i += 1
                If Not FileExists($sFileName & '(' & $i & ')') Then
                    $sFileName = $sFileName & '(' & $i & ')'
                    ExitLoop
                EndIf
            WEnd
        Else
            While 1
                $i += 1
                If Not FileExists($sTmp[1] & '(' & $i & ')' & $sTmp[2]) Then
                    $sFileName = $sTmp[1] & '(' & $i & ').' & $sTmp[2]
                    ExitLoop
                EndIf
            WEnd
        EndIf
    EndIf
    $iFileOp = FileOpen($sFileName, 16 + 2)
    If @error Then Return SetError(2, 0, -1)
    FileWrite($iFileOp, $sBuff)
    If @error Then Return SetError(3, 0, -1)
    FileClose($iFileOp)
    If $iSplash Then TrayTip('_FileReceive', 'Succesfull!', 1, 1)
    TCPCloseSocket($iAccSocket)
    TCPShutdown()
    Sleep(1000)
    Return 1
EndFunc   ;==>_FileReceive

I hope that someone will give me clues to make it work or accept to send or receive files for test it

Cheers, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites



Have a look here.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

@Andreik

Thanks for your link :)

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0