This topic is now archived and is closed to further replies.


.NET library for Utorrent WebUI

Recommended Posts

I'm developing a .NET library for the UTorrent WebUI, you'll find it on a svn :

Login : utorrent / utorrent

It comes with a very simple Gui, to show how to use the lib with windows forms.

Simple gui example :


Edit2: For IE only online Gui launcher : Here

P.S: if you have some time feel free to help :P

P.S 2 : Not really documented yet.

Share this post

Link to post
Share on other sites

Jipy, I get:

svn import "" --username utorrent --password utorrent

svn: MKACTIVITY of '/UTorrentLib/!svn/act/1ade8b64-ca84-7747-b62b-3f93a7c63904': 403 Forbidden (

Can you confirm access from external IP's?




dammit. wrong command - ignore me!

svn checkout "" --username utorrent --password utorrent

Share this post

Link to post
Share on other sites

Hi Jippy..

I have downloaded and started to use your code in a attempt enclose the webiu within an ASP.NET 2.0 webapplication (this to higher the security level, i my case let IIS, windows server & security policies handle brute force attack etc.).

Doing this I have used your nice code.

However I have changed som of your code (e.g refactored the 'UpdateLists' method and added a mtheod called 'StartNewTorrent' within the TorrentSession class.)

If you are intressted in the changes / additions (or want a look at the ASP.NET project in progress please let me know)

Best regards!


Share this post

Link to post
Share on other sites

Hi smithimage, i try make web app on uTorrent Web UI with multiuser, forum, statistics and other features. I tryed Jippy's library, but I had some problems.

I´m interested in your project and I can help you with developing. Could you tell me something about your idea and show me your project?

Thanks, Lukas.

Share this post

Link to post
Share on other sites

Ok I've been busy lately, I've just moved in Montreal.

I'll resume my work on the lib starting tomorrow. I'm interrested in your changes, can you contact me by msn or mail (jipy666(at)hotmail(dot)com)

Share this post

Link to post
Share on other sites

Hi there Jipy and taxik.

I have now published my work and the changes I made at this address :

My basic idea was / is just to make it "safely", publicly (but restricted) publishable on a windows server (i.e. asp.NET). This since the security implemented in the webui as is don't implement any brute force security checks (as far as I could figure out anyhow). My idea is just to use the C# UTorrentlib and wire a simple (ajax enabled) UI around the UTorrentlib and let IIS-folder security and security policies (or any other security solution usable within the handle multiple faulty login tries (with lookout rules).

This by publicly publish this restricted application on my webserver (on port 80) having the UTorrent WebUI running behind the firewall on a port not publicly visable from outside the firewall.

Please have in mind this is a work in progress just started, but don't hesitate to make any remark in regard to the idea or problem solution..

Best regards!


Share this post

Link to post
Share on other sites

Hi smithimage, good job...

I like your WebUI. Do you have a new realease? Because I must start on my multiuser WebUI. I have extern app, that can start torrents to directory of every user, but I need UI with better loggin and with session of every user.


Share this post

Link to post
Share on other sites

hi everyone

I have downloaded this .net code. I get hazy when i debug it and check for UTorrentStatus field in torrent object. I found its 233/201. it means more than 1 state is set in that long variable. why is it like this? 233 means start,pause states are set. but the torrent is in pause mode. i can find out by ANDing it but the problem is when both are set in 233 case what should i take?

one more thing. start,stop,pause actions do not update internal data structures about modified torrents. The code given here calls updateLists() periodically and updates internal structures which reflect new values. I dont want to call updateList() periodically in my project. to overcome this problem what i did is , i called updateLists() method whenever i do any action(like start,stop,pause) on any torrent.

somebody pls help me out

Share this post

Link to post
Share on other sites


When we add a torrent file from webUI it makes a HTTP POST request and sends the torrent file right. I have done multipart/form-data post but the result is error.Torrent logger shows "?action=add-file" in its log, but that doesn't mean success or failure. I did not find this piece of code in the .NET library i downloaded here. pls find the c# code here and correct me where i'm wrong.

c# code


HttpWebRequest ts = (HttpWebRequest)HttpWebRequest.Create("http://" + this.m_strHostname + ":" + this.m_iPort.ToString() + "/gui/" + request);

ts.KeepAlive = false;

ts.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(this.m_strUsername + ":" + this.m_strPassword)));

string postdata = "";

string boundary = "------------------------BoundaryLine";

postdata += "\r\n"+"--" + boundary + "\r\n";

postdata += "Content-Disposition: form-data; name=\"file\" filename=\""+new FileInfo(torrentFilePath).Name+"\""+"\r\n";

postdata += "Content-Type: application/x-bittorrent" + "\r\n";//+ getContentType(@torrentFilePath) + "\r\n";

postdata += "" + "\r\n";

char[] chartowrite1 = postdata.ToCharArray();

byte[] w1 = Encoding.ASCII.GetBytes(postdata);

postdata = "\r\n" + "--" + boundary + "--\r\n";

char[] chartowrite2 = postdata.ToCharArray();

byte[] w2 = Encoding.ASCII.GetBytes(postdata);

//fileBytes contains the torrenfile contents . its type is byte[]

byte[] bytesToWrite = new byte[w1.Length + w2.Length + fileBytes.Length];

int index = 0;

for (int i = 0; i < w1.Length; i++)


bytesToWrite[index + i] = (byte)w1;


index += w1.Length;

for(int i=0; i<fileBytes.Length;i++)




index += fileBytes.Length;

for (int i = 0; i < w2.Length; i++)


bytesToWrite[index + i] = (byte)w2;


ts.Method = "POST";

ts.ContentType = "multipart/form-data; boundary=" + boundary;

ts.ContentLength = bytesToWrite.Length;

Stream writeStream = ts.GetRequestStream();

writeStream.Write(bytesToWrite, 0, bytesToWrite.Length);


resp = (HttpWebResponse)ts.GetResponse();

StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);

String response = responseReader.ReadToEnd();

Object GuiResp = JavaScriptConvert.DeserializeObject(response);


data posted looks like this.


Content-Disposition: form-data; name="file" filename="TorrentSession.cs.torrent"

Content-Type: application/x-bittorrent

d10:created by13:uTorrent/177013:creation datei1213169314e8:encoding5:UTF-84:inf

od6:lengthi12615e4:name17:TorrentSession.cs12:piece lengthi65536e6:pieces20:?6?"




in the content-disposition i tried name="torrent_file" also but of no use.

GuiResp at the end of code shows error as the response.

some one pls help me out adding torrent

Share this post

Link to post
Share on other sites


This looks great but i am getting an error when testing your sample. IT also happens when i call the code in my version.

here is the error

"The given key was not present in the dictionary."

this is the line throwing the exeption

JavaScriptArray mjsTorrents = (JavaScriptArray)GuiResp["torrentp"]; // More code below

here is the code sample generating the error:

 public void UpdateLists()

//Sending request and retrieving response.
JavaScriptObject GuiResp = GetResponseFromUi("?list=1&cid=" + this.m_strLastCache);
this.m_strLastCache = (String)GuiResp["torrentc"];
//Creating a List of the modified torrents.
List<JavaScriptArray> mTorrents = new List<JavaScriptArray>();
JavaScriptArray mjsTorrents = (JavaScriptArray)GuiResp["torrentp"];
for (int i = 0; i < mjsTorrents.Count; i++)

and full exeption detail

System.Collections.Generic.KeyNotFoundException was unhandled

Message="The given key was not present in the dictionary."



at System.ThrowHelper.ThrowKeyNotFoundException()

at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

at UTorrentLib.TorrentSession.UpdateLists() in C:\Users\Tyron\Desktop\New Folder\UTorrentLib\TorrentSession.cs:line 122

at UtorrentApp.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Tyron\Documents\Visual Studio 2008\Projects\Utorrent\Utorrent\Form1.cs:line 28

at System.Windows.Forms.Form.OnLoad(EventArgs e)

at System.Windows.Forms.Form.OnCreateControl()

at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)

at System.Windows.Forms.Control.CreateControl()

at System.Windows.Forms.Control.WmShowWindow(Message& m)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ContainerControl.WndProc(Message& m)

at System.Windows.Forms.Form.WmShowWindow(Message& m)

at System.Windows.Forms.Form.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)

at System.Windows.Forms.Control.SetVisibleCore(Boolean value)

at System.Windows.Forms.Form.SetVisibleCore(Boolean value)

at System.Windows.Forms.Control.set_Visible(Boolean value)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

at System.Windows.Forms.Application.Run(Form mainForm)

at UtorrentApp.Program.Main() in C:\Users\Tyron\Documents\Visual Studio 2008\Projects\Utorrent\Utorrent\Program.cs:line 19

at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()


Share this post

Link to post
Share on other sites


I have a reason why you are getting KeyNotFoundException. If the response from utorrent client doesn't contain records for "torrentp", you will get this exception. Because without checking whether there is any record with key "torrentp" you are trying to get results for it. The code which you have is outdated. There is a new code for updateList() where there is check for the key something like below

JavaScriptObject GuiResp = GetResponseFromUi("?list=1&cid=" + this.m_strLastCache);

this.m_strLastCache = (String)GuiResp["torrentc"];

//Creating a List of the modified torrents.

List<JavaScriptArray> mTorrents = new List<JavaScriptArray>();



JavaScriptArray mjsTorrents = (JavaScriptArray)GuiResp["torrentp"];

for (int i = 0; i < mjsTorrents.Count; i++)





If any of you have code to POST torrent file pls share with me. I need it immediately

Share this post

Link to post
Share on other sites

I haven't done .Net programing in a while, but I can offer you the way to do it in Javascript

should be simple enough to change around to either C# or whatever language you use in your .Net

well, lets just say your also missing a semicolon after your file="torrent_file"

but otherwise I can't really see much of an error in your coding...

and IDK about this, wouldn't it be easier to create a binaryWriter than to convert it using that method. Also just for pretifying code, wouldn't it be easier to create a function to write your bytes for you, i mean you are essentially calling the same code 3 times. Bleh, nvm me I'm not the one to talk about making code efficient :). Anyways... I think thats your problem though, i haven't really tested it... But thats what I think you are missing the semicolon.

BTW >>> code is from the uTorrent firefox extension, and isn't written by me

var multipartBoundary = "=*=*=*=*=*=";

function writeBinary(ostream, string)
for(i=0; i != string.length; ++i)

function addTorrent(uri, torrentData)
var body = Components.classes[";1"]
body.init(1024, 1024*1024, null);
var bodyOutput = body.getOutputStream(0);
var bodyBinary = Components.classes[";1"]

var filename = getFilenameFromUri(uri);

"--" + multipartBoundary + "\r\n" +
"Content-Disposition: form-data; name=\"torrent_file\"; filename=\"" + filename + "\"\r\n" +
"Content-Type: application/x-bittorrent\r\n" +
writeBinary(bodyBinary, torrentData);
writeBinary(bodyBinary, "\r\n--" + multipartBoundary + "--\r\n");

var request = new XMLHttpRequest();"POST", gUTorrentPrefs.getConnectionType() + "://" + gUTorrentPrefs.serverAddress() + ":" + gUTorrentPrefs.serverPort() +
"/gui/?action=add-file", true, gUTorrentPrefs.adminUsername(), gUTorrentPrefs.adminPassword());
request.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + multipartBoundary);
request.onreadystatechange = function(event)
if (request.readyState == 4)
if (request.status == 200)
var response = request.responseText.parseJSON();
var message = response.error;
if (message != null)
displayError("uTorrent responded with an error for torrent \"" + uri.spec + "\". The error was: " + message);
displayError("Error uploading torrent file \"" + uri.spec +
"\" to uTorrent. Error code was " + request.status + ".");

var bodyInput = bodyOutput.newInputStream(0);

Share this post

Link to post
Share on other sites

Hi everyone,

What ever became of this library?

I am looking for a way to hook into uTorrent, which I found has to be the webUI. I then found references to this wrapper, which I would like to check out. However I am not able to get contact to the SVN and checkout the source using TortoiseSVN.

Can anyone confirm if this project is dead or still in development?



Share this post

Link to post
Share on other sites