Suggestion for Send-file in MUSHclient

Posted by Fenix on Tue 02 Mar 2004 07:51 AM — 3 posts, 12,924 views.

Netherlands #0
In my opinion, it would be a nice added feature to have a possible variable substitution in the option 'send file'.

Currently, i have the need to send a larger number of files to our testmud (which has no ftp-connection). If I could state in the 'send this at the start'-section the text like:

ed $filename
a

to start the editor with the uploading filename (and start appending to the file), that would shorten the time needed to upload all my files.

In addition, sending multiple files would be nice too (of course, that HAS to be in combination with the filename :)

Fenix
Australia Forum Administrator #1
You can do that with a bit of scripting. I have done an example alias to do it. Here it is ...


<aliases>
  <alias
   match="^sendfile (.*?)( .*?)?$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Dim FSO, TexttFile, sContents, sFileName, LineArray, L

  sFileName = "%1"
  sRemoteFileName = sFileName 

'
'  We can have a different file name at the destination
'

  if "%2" &lt;&gt; "" Then
    sRemoteFileName = "%2"
  end if

'
'  Get a FileSystemObject
'
  Set FSO = CreateObject("Scripting.FileSystemObject")

'
'  Open the file
'
  On Error Resume Next
  Set TexttFile = FSO.OpenTextFile(sFileName,1)

'
'  Check for error opening it
'
  If Err.Number &lt;&gt; 0 Then
    ColourNote "white", "red", "Could not open file: " &amp; sFileName 
    ColourNote "white", "red", Err.Description
    On Error GoTo 0 
  Else

    On Error GoTo 0 

'
'  Read contents
'
    Contents = TexttFile.ReadAll
    TexttFile.Close

    Set TexttFile = Nothing

'
'  Split file into lines at carriage return, line feed
'

    LineArray = Split (Contents, vbCrLf)

'
'  Tell remote end to edit this file and append to it
'

   Send "ed " &amp; sRemoteFileName  ' edit it
   Send "%d"                     ' delete existing content
   Send "a"                      ' append to it

'
'  Go through a line at a time
'

    For Each L in LineArray
    
'
'  Lines consisting of only a period will exit editing, change them
'

      If trim (L) = "." Then
        L = ". "
      End If

'
'  Send this line
'
      Send L

    Next

    Contents = ""

    Send "."   ' a period exits append mode
    Send "w"   ' write the file
    Send "q"   ' quit the editor

    ColourNote "white", "blue", "Sent file:   " &amp; sFileName 
    ColourNote "white", "blue", "Remote name: " &amp; sRemoteFileName 
    ColourNote "white", "blue", "Sent " &amp; ubound (LineArray) &amp; " lines."
    LineArray = ""  ' save memory by discarding array 

  End If  ' no error on open

  Set FSO = Nothing

</send>
  </alias>
</aliases>



To use this you type:


sendfile (name)


or


sendfile (local-name) (remote-name)


eg.


sendfile comms.c


or


sendfile d:/source/comms.c comms.c



Then you could make a second alias that does a batch, by doing something like this:

sendfile d:/source/comms.c comms.c
sendfile d:/source/fight.c fight.c

(You would send this alias to "execute" so it would be re-evaluated).

The way I have written it, I assumed you are sending to a server with the Unix "ed" command available. If not, you might need to modify it slightly.

Also, be cautious that it doesn't try to slow down the delivery rate. You conceivably might lose data if you try to send too many files at once, particularly if they are large.

Maybe send them in batches, or put in a delay between files.
Amended on Tue 02 Mar 2004 09:48 PM by Nick Gammon
Netherlands #2
Excellent, I made some slight modifications to accomodate possible typing errors (using 'trim' in the assignment of the local/remote filename). I definitly should check out the scripting-possibilities of this client.

Thanks

Fenix

--
Lord Fenix of the Force
KoBra Mud
(kobra.et.tudelft.nl:23)