Jump to content

File save without popup in tcp?


Recommended Posts

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

Link to comment
Share on other sites

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 :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...