Subscribe to Nova Dragoon's Blog        RSS Feed
-----

File transfer with XMLRPC

Icon 1 Comments
Part of my project is a service where you upload your built RPM package directly into a repository.
XMLRPC facilitated this excellently with BASE64 encodings:


on the PHP XMLRPC server:

function uploadFile($method_name, $params, $user_data) {
	$file = "/var/www/fedora/linux/tcc/testing/7/i386/" . $params[0];
	$file_data = $params[1];
	$file_data=base64_decode($file_data);
	$fh = @fopen($file, "wb");
	if ($fh) {
		if (@fwrite($fh, $file_data)) {
			$msg = "File Upload Complete";
		} else {
			$msg = "Error Uploading File";
		}
		fclose($fh);
		return $msg;
	} else {
		return "Error Uploading File";
	}	
}



and the client side in Python Xmlrpclib

def uploadFile(server,opts):
	basename=os.path.basename(opts[0])
	fin = open(opts[0])
	fout= open("/tmp/rpmupload.tmp","w")
	base64.encode(fin,fout)
	fin.close()
	fout.close()
	fin=open("/tmp/rpmupload.tmp")
	base64string=fin.read()
	fin.close()
	os.unlink("/tmp/rpmupload.tmp")
	print server.uploadFile(basename,base64string)



I have to do a little file shuffling on the client side to give the base64 libs what they want. But thats really all the code needed.

Now RPM devs don't have to scp and login and shuffle files around searching directories, and messing up file permissions.

MAGIC!

1 Comments On This Entry

Page 1 of 1

Guest

22 May 2008 - 08:49 AM
XPr2B2 <a href="http://hbqjakmopsbo.com/">hbqjakmopsbo</a>, vnyupvtdlpjn, [link=http://vaovzsunuapi.com/]vaovzsunuapi[/link], http://yqxdrgotdcms.com/
0
Page 1 of 1

Search My Blog

Recent Entries

Recent Comments

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)