You are not logged in.

#1 2012-01-24 20:38:27

Butcher
Member
Registered: 2009-02-04
Posts: 158

Script to upload a file using SCP

Hello, I made these two scripts to upload files to a remote server using ssh:

up() {
	R=$(perl -le 'print map { unpack "H*", chr(rand(256)) } 1..2').$(perl -e "\$ext = \"$1\"; \$ext =~ s/.*\.(.*)\$/\$1/; print \$ext")
	scp "$*" myserver.net:/var/www/myserver.net/$R
	echo http://myserver.net/$R
	echo -n http://myserver.net/$R | xclip -selection clipboard
}

upc() {
	scp "$*" myserver.net:/var/www/myserver.net
	echo http://myserver.net/$*
	echo -n http://myserver.net/$* | xclip -selection clipboard
}

up() uploads the file with a random name and upc() uploads the file with the same name it had in my machine.
But these scripts are real crap; upc() won't work with files with spaces and will output a wrong name when uploading files that are in a directory different from $PWD and up() doesn't work when the file is in $PWD, so I have to use `up ./file.png`.

Can you provide me a better solution or other scripts? Thank you.

Offline

Board footer

Powered by FluxBB