You are not logged in.

#101 2010-02-25 18:49:20

Ape
Member
From: Finland
Registered: 2009-10-15
Posts: 46
Website

Re: quickserve - easy ad-hoc file sharing

Polling for new files in a folder (and automatically sharing also them) would be really useful.

Offline

#102 2010-02-25 19:01:08

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

@agapito
Is it possible to stream using standard HTTP requests?

@Ape
It already does that.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#103 2010-02-25 19:37:29

agapito
Member
From: Who cares.
Registered: 2008-11-13
Posts: 641

Re: quickserve - easy ad-hoc file sharing

Lol, i don't know. I was asking you... It would be a nice feature if could be implemented.


Excuse my poor English.

Offline

#104 2010-02-27 04:22:23

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: quickserve - easy ad-hoc file sharing

I wrote the following script to share files from file manager (using quickserve, of course).  The problem is if the script is run from file manager, when the script finish, the terminal close, quickserve is also killed.  When I run the script in terminal, I can close the terminal after the script finish and quickserve is still running.  I'm a rookie at writing bash script, so I'm sure I must have missed something.  Please give me some pointers to start quickserve in the background.  Here is my code:

#!/bin/bash

function choose {
    PID=`netstat -antuwp|grep -o $PORT.*python|awk '{print $4}'|cut -d'/' -f1`
    TEXT="User: $USER \nPassword: $PASS \nPort: $PORT \nPID: $PID"
    [ $PID ] && ACTION="Stop quickserve" || ACTION="Start quickserve"
    i=`$D --menu "$TEXT" 0 0 0 1 "Edit list" 2 "$ACTION"`
    case $i in
        1) $EDITOR $LIST ;;
        2) [ $PID ] && kill $PID || startqs ;;
        *) exit
    esac
    choose
    }

function startqs {
    [ $PID ] || quickserve -f $LIST -p $PORT --infopage=/info --upload=/home/tri/download -u $USER --password=$PASS &
    sleep 2
    }

if tty -s; then
    LIST=/home/user/.quickservefiles
    D="dialog --stdout --title quickserve"
    PORT=5905
    USER=user
    PASS=password
    PID=`netstat -antuwp|grep -o $PORT.*python|awk '{print $4}'|cut -d'/' -f1`
    if [ $# -gt 0 ]; then
        if [ -f $LIST ]; then
            i=`$D --menu "A list of shared files already existed." 0 0 0 1 "Start new list" 2 "Add to existing list"`
            echo $i
            case $i in
                1) rm $LIST ;;
                2) ;;
                *) exit 1
            esac
        fi
        for FILE; do
            [[ "$FILE" = /* ]] && echo "$FILE" >> $LIST || echo $PWD/"$FILE" >> $LIST
        done
        startqs
    else
        choose
    fi
else
    mrxvt -e $0 "$@" &
fi

Offline

#105 2010-02-27 16:43:36

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

Is "file manager" the name of the application or are you referring to a specific file manager?

From a quick glance at the script it looks fine and if it runs as expected from the terminal, the problem probably lies with the application that you're using to launch it, so without knowing exactly which one, I don't have any pointers to give (and might not even if I did know as I tend to run most things from the terminal or via gmrun).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#106 2010-02-27 16:56:00

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: quickserve - easy ad-hoc file sharing

The file manager is pcmanfm, but I think it will be the same for any graphical file manager.  So how I'm using this is highlight the files I'd like to share in pcmanfm, right click, choose open with the script above.  The script runs in terminal and as long as terminal remains open, quickserve is running, but if terminal is close, quickserve stop.  Can you add an option to run quickserve as daemon (-d)?

Offline

#107 2010-02-27 17:33:47

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: quickserve - easy ad-hoc file sharing

Try running 'disown' after you start quickserv

Offline

#108 2010-02-27 17:46:41

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: quickserve - easy ad-hoc file sharing

I replace "sleep 2" with "disown", but it still doesn't work.  I added "read" after "disown" to keep the terminal open, and quickserve is running while terminal is open, but when I press "enter", terminal close, quickserve stop.

Offline

#109 2010-02-27 17:47:51

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

I'm looking into this right now but so far it seems that the amount of code that I would need to add to enable daemonization is non-trivial. You can get an idea from the following links:

http://www.jejik.com/articles/2007/02/a … in_python/
http://code.activestate.com/recipes/278 … ython-way/

I'm also playing around with the Bash script (e.g. with disown) to try to get it to behave properly as that seems to be the simpler approach in this case.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#110 2010-02-27 18:00:22

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: quickserve - easy ad-hoc file sharing

That is a lot of additional codes to daemonize it.  I don't understand why it works when the script is run fine from terminal but doesn't work when run from file manager.  Somehow quickserve PID is tied to "mrxvt -e $0 "$@ &" PID?

Offline

#111 2010-02-27 18:29:37

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

I'm giving up on this for now because I don't have any more time to play with it. It might be worth posting this as a Bash question in the general programming forum.

I'll look into daemonizing the script again later and may take the opportunity to modularize the code to avoid redundancy with Voracious. The only downside to that approach is that neither would remain a single-file script.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#112 2010-03-05 22:10:54

tri1976
Member
Registered: 2009-09-07
Posts: 152

Re: quickserve - easy ad-hoc file sharing

tri1976 wrote:

...run quickserve in the background.....

It's solved...the magic command is nohup.  So the command for running quickserve in background is something like this

nohup quickserve [options] > /dev/null 2>&1 &; sleep 1

"sleep 1" is needed or quickserve process is still terminated after the shell is closed.

Last edited by tri1976 (2010-03-06 00:44:56)

Offline

#113 2010-03-06 00:39:29

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

Thanks for posting the solution. I had tried nohup but only without the sleep command (obviously).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#114 2010-05-17 19:31:53

sconosciuto
Member
Registered: 2010-05-17
Posts: 1

Re: quickserve - easy ad-hoc file sharing

I think it's better to add a warning after the Upload button is pressed. A simple javascript can do that:

<body>
  <div id="wrapper">
    <h1>Upload%(backlink)s%(morelink)s%(fewerlink)s</h1>
    <div id="form_wrapper">
      <form action="%(back)s" enctype="multipart/form-data" method="post">
        %(fields)s
        <input class="submit" type="submit" value="Upload" onclick="document.getElementById(\'uploading\').style.display=\'\';"><br><br>
    <div id="uploading" style="display:none;text-align:center">Please wait while your file is uploading</div>
      </form>
    </div>
  </div>
</body>

Offline

#115 2010-05-18 01:20:26

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

Thanks, sconosciuto. I've added it to the latest release.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#116 2010-05-18 02:47:37

ntness
Member
From: The World
Registered: 2009-12-29
Posts: 97

Re: quickserve - easy ad-hoc file sharing

Just found this little gem and can't wipe the smile from my face...it's so simple. Thanks much for writing this! smile


transcend to the fifth abode

Offline

#117 2010-07-13 20:00:52

FSX
Member
Registered: 2009-08-06
Posts: 57

Re: quickserve - easy ad-hoc file sharing

I'm using the latest version from the AUR and I found a bug.

It send a wrong mimetype to the browser. Something like ('text/html', None). It's because geuss_type() returns a tuple with the mimetype and the encoding. It was fixed for me when I replaced the following on line 277:

    if not mimetype:
      mimetype = 'application/octet-stream'

With:

    if not mimetype:
      mimetype = 'application/octet-stream'
    else:
      mimetype = mimetype[0]

Offline

#118 2010-07-14 04:42:50

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

@ntness
Thanks for the feedback. smile (Sorry for the late reply. I somehow missed your post.)

@FSX
Thanks. I've fixed it along with a few other bugs that I found and added some other features while I was at it.

## Changelog

### 2010.07.14
* added threading support to handle multiple connection simultaneously
* fixed "Content-Range" bug
* added support for HEAD requests
* re-organized HTML generation
    - cleaner code
    - W3C XHTML Validation
    - W3C CSS Validation
* re-organized startup and info page output
* added icon
* fixed MIMEtype detection bug
* added "Content-Encoding" header

added bonus: media players can now seek through files


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#119 2010-08-04 18:09:03

kgas
Member
From: Qatar
Registered: 2008-11-08
Posts: 718

Re: quickserve - easy ad-hoc file sharing

kjon wrote:

Xyne, this is a very nice app... xD

However, I got this message when sharing a directory with non english characters.

----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 33302)
Traceback (most recent call last):
  File "/usr/lib/python2.6/SocketServer.py", line 281, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 307, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.6/SocketServer.py", line 615, in __init__
    self.handle()
  File "/usr/lib/python2.6/BaseHTTPServer.py", line 329, in handle
    self.handle_one_request()
  File "/usr/lib/python2.6/BaseHTTPServer.py", line 323, in handle_one_request
    method()
  File "/usr/bin/quickserve", line 102, in do_GET
    self.wfile.write(html.encode("utf-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 36: ordinal not in range(128)
----------------------------------------
^C^C received, shutting down server

Is there a way to solve this issue? Thanks.

I got the similar error with the current package build in AUR.

Offline

#120 2010-08-04 19:59:11

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

kgas wrote:

I got the similar error with the current package build in AUR.

Please post the exact error message and the name of the directory or file that you are trying to serve. Based on your location I assume that you are using Arabic and have therefore tried to reproduce this with both directories and files named "عربي" in various levels of nesting, with and without regular names. I was unable to reproduce the error.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#121 2010-08-05 14:21:13

kgas
Member
From: Qatar
Registered: 2008-11-08
Posts: 718

Re: quickserve - easy ad-hoc file sharing

thanks for your response and sorry for the delay.

>quickserve  --port=1998  --filelist=MonthlyExpences2010.ods --username=un  --password=test

    I am not sure why it is printing all the file data like cat.

      雃ٙRcD3.?{*vϩHa>@O20G՞ط:"e}τjX샔w'Ǔ8a
                                                     :D笱l
Press <Ctrl-C> to exit.

virgo.lan - - [05/Aug/2010 17:07:18] "GET / HTTP/1.1" 401 -
----------------------------------------
Exception happened during processing of request from ('192.168.1.71', 50785)
Traceback (most recent call last):
  File "/usr/lib/python2.6/SocketServer.py", line 558, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.6/SocketServer.py", line 615, in __init__
    self.handle()
  File "/usr/lib/python2.6/BaseHTTPServer.py", line 329, in handle
    self.handle_one_request()
  File "/usr/lib/python2.6/BaseHTTPServer.py", line 323, in handle_one_request
    method()
  File "/usr/bin/quickserve", line 145, in do_GET
    self.do_GET_or_HEAD(True)
  File "/usr/bin/quickserve", line 182, in do_GET_or_HEAD
    if os.path.isdir(paths[k]):
  File "/usr/lib/python2.6/genericpath.py", line 41, in isdir
    st = os.stat(s)
TypeError: stat() argument 1 must be encoded string without NULL bytes, not str
----------------------------------------

language is English only. I don't speak  Arabic.

Offline

#122 2010-08-05 16:01:26

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

kgas wrote:

thanks for your response and sorry for the delay.

>quickserve  --port=1998  --filelist=MonthlyExpences2010.ods --username=un  --password=test

    I am not sure why it is printing all the file data like cat.

      雃ٙRcD3.?{*vϩHa>@O20G՞ط:"e}τjX샔w'Ǔ8a
                                                     :D笱l
...
TypeError: stat() argument 1 must be encoded string without NULL bytes, not str
----------------------------------------

If you want to share the file "MonthlyExpences2010.ods", remove "--filelist=". The "--filelist" option specifies a file that contains a list of files to share.

Example:
If you want to share "/tmp/foo" and "/tmp/bar", then you would simply run

quickserve /tmp/foo /tmp/bar

Now if you want to stop serving "/tmp/bar" and start serving "/tmp/baz" instead, you would have to restart the server with the new arguments. This is why there is a "--filelist" option. It lets you change the settings dynamically. Using the files in the previous example, you would first create a list, e.g.:

/tmp/serve.txt

/tmp/foo
/tmp/bar

then start the server:

quickserve --filelist=/tmp/serve.txt

Now to stop serving "/tmp/bar" and start serving "/tmp/baz", you would just edit "/tmp/serve.txt":

/tmp/serve.txt

/tmp/foo
/tmp/baz

Quickserve will detect that the file has been updated and begin serving the files in the new list.


The error was caused by the unexpected NULL bytes in the .ods file, which also jumbled the console output when it tried to print the "paths" in that file.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#123 2010-08-05 17:54:29

kgas
Member
From: Qatar
Registered: 2008-11-08
Posts: 718

Re: quickserve - easy ad-hoc file sharing

now clear, thanks.

Offline

#124 2010-09-18 11:14:14

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: quickserve - easy ad-hoc file sharing

I've added SSL (HTTPS) support and moved the base server to it's own module to avoid code reduplication with voracious. I may have introduced new bugs with the numerous changes.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#125 2010-09-18 11:28:31

kgas
Member
From: Qatar
Registered: 2008-11-08
Posts: 718

Re: quickserve - easy ad-hoc file sharing

nice. I will try this.

now the normal one gives the following error when i put the username and password. without username/password server starts fine

 
quickserve --filelist=/home/<user>/Documents/ToExport.txt --port=2005 --password=test
Starting quickserve...
  address: all interfaces
  port: 2005
  pid: 27637
  authentication
Traceback (most recent call last):
  File "/usr/bin/quickserve", line 528, in <module>
    main(options.address, options.port)
  File "/usr/bin/quickserve", line 462, in main
    server.display_status()
  File "/usr/lib/python2.6/site-packages/XyneHTTPServer.py", line 94, in display_status
    print "    password: " + options.password
NameError: global name 'options' is not defined

Last edited by kgas (2010-09-18 12:11:58)

Offline

Board footer

Powered by FluxBB