Posts Tagged: perl


14
Feb 08

Getting Files to Remote Places

Every now and then I need to share files with others. Either need to upload something to an accessible place or just give somebody a link to a set of files. Two handy scripts:

[perl]### BASH function, copy to ~/.bashrc ###
putfile(){
basename=${1##*/}
scp $1 user@host:/home/user/public_html/tmp/$basename
echo http://host/tmp/$basename
}[/perl]

Now this function is accessible from the terminal session. Just write putfile fileName and it will scp the file to the remote machine and output the URL that you can give to your friends. Be sure to have key based authentication enabled.

Do you want to quickly share a folder from your HDD without creating a quick link to your /var/www? Fire up a webserver with python.
[python]
python -c "from SimpleHTTPServer import test; test()"
[/python]

You can't remember you ip or don't want to type it every time to give the link? Echo the IP also to your console. Mind that this example uses the eth1 device, so if you have a different one be sure to change it.

[python]
### add it to ~/.bashrc
alias web='python -c "from SimpleHTTPServer import test;
import socket,fcntl,struct;
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
print \"http://\"+socket.inet_ntoa(fcntl.ioctl(
s.fileno(),0x8915, struct.pack(\"256s\", \"eth1\"))[20:24])+\":8000\";
test()"'
[/python]

Now you can share any folder by just typing web and you can copy the URL to your friend on LAN.