Jump to content
Sign in to follow this  
Glyph

File save without popup in tcp?

Recommended Posts

Glyph

Dim $iMainSocket = -1, $iSocket = -1
Dim $buffer = ""
Dim $bytes = -1
Dim $iRet = -1

TCPStartup()

$iMainSocket = TCPListen(@IPAddress1,5656)

While 1
    If $iSocket = -1 Then
        $iRet = TCPAccept($iMainSocket)
        If Not @error Then $iSocket = $iRet
    Else
        $buffer &= TCPRecv($iSocket,4096)
        If $bytes = -1 And StringInStr($buffer,",") Then
            $bytes = StringLeft($buffer,StringInStr($buffer,",")-1)
            $buffer = StringTrimLeft($buffer,StringInStr($buffer,","))
        Else
            If StringLen($buffer) = $bytes Then 
               [i] $FileReceived = FileSaveDialog("File save",@DesktopDir,"All (*.*)") [/i]
                ExitLoop
            EndIf
        EndIf
    EndIf
WEnd

FileDelete($FileReceived)
FileWrite($FileReceived,$buffer)

MsgBox(4096,"","Transfer Complete "&$FileReceived&" Saved from socket "&$imainsocket)
TCPShutdown()
run("Test.exe")
Exit

How would i have it save " $FileReceived = FileSaveDialog("File save",@DesktopDir,"All (*.*)") "

without the dialog, i can't be at my server 24.7 to accept the popup... so i need a way to accept the text file without a popup. i don't see anything in the help file either!


tolle indicium

Share this post


Link to post
Share on other sites
enaiman

Not tested but it should work - I've used FileCopy instead.

Dim $iMainSocket = -1, $iSocket = -1
Dim $buffer = ""
Dim $bytes = -1
Dim $iRet = -1
Dim $FileReceived = @DesktopDir&"\temp_receive.txt"

TCPStartup()

$iMainSocket = TCPListen(@IPAddress1,5656)

While 1
    If $iSocket = -1 Then
        $iRet = TCPAccept($iMainSocket)
        If Not @error Then $iSocket = $iRet
    Else
        $buffer &= TCPRecv($iSocket,4096)
        If $bytes = -1 And StringInStr($buffer,",") Then
            $bytes = StringLeft($buffer,StringInStr($buffer,",")-1)
            $buffer = StringTrimLeft($buffer,StringInStr($buffer,","))
        Else
            If StringLen($buffer) = $bytes Then
                FileClose(FileOpen($FileReceived, 2))           ;clear the file content
                FileWrite($FileReceived,$buffer)
                FileCopy($FileReceived, @DesktopDir&"\file_received_"&@MDAY&"-"&@MON&"-"&@YEAR&" "&@HOUR&"h"&@MIN&".txt", 9)    ;change here whatever suits you
                ExitLoop
            EndIf
        EndIf
    EndIf
WEnd

;FileDelete($FileReceived)                  ;you don't need these anymore
;FileWrite($FileReceived,$buffer)

MsgBox(4096,"","Transfer Complete "&$FileReceived&" Saved from socket "&$imainsocket)
TCPShutdown()
run("Test.exe")

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
Glyph

Awesome!, I didn't realize a filecopy would work... i actually thought about that too, but didn't try it!

Edited by backstabbed

tolle indicium

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  

×