Darin Fisher wrote:
there's some sample code here:...[snip]...
http://lxr.mozilla.org/mozilla/source/netwerk/test/TestProtocols.cpp
which shows you how to load any URL using necko (mozilla's networking library). for FTP upload, check out this sample code:
http://lxr.mozilla.org/mozilla/source/netwerk/test/TestUpload.cpp
again, this sample code is not particular to FTP and will work just as well with HTTP PUT.
and, of course feel free to ask questions! :)
darin
Thanks for the speedy reply! I do have a couple of other questions:
1. Can this all be done in Javascript alone? I would like to make a javascript prototype (class) for an FTP session that has a method/function that allows you to pass a FTP URL to as well as USERNAME/PASSWORD and a DOM object for upload to a FTP server. I can serialize the DOM to a string or whatever if neccessary. Is creating something like this viable in Javascript? My C programming skills are just not there yet but Javascript I can write in my sleep.
2. I am a little confused about all the components that go into establishing an FTP session and uploading a file. I have looked through all the links you listed and am going through the XPCOM Network interface documentation at xulplanet.com. Things are slowly making sense but what is the sequence of steps? i.e. A) create a (FTP)Channel using the IOService, B)Create a URI instance and somehow plug it into the channel... I'm lost.
I really just want a function I can access from Javascript, as mentioned above, that I can use to upload a simple xml text file, and possibly binary also. Am I out to lunch? I figure if its being done Mozilla Composer it must be possible! I would also like to submit the finished product to the mozdev JSLib project for other developers future use.
any help is most appreciated - mawrya
something like this might do the trick: (note: i have not tested this at all.)
function MyListener() {} // constructor
MyListener.prototype = {
QueryInterface: function(iid)
{
if (!iid.equals(Components.interfaces.nsISupports) &&
!iid.equals(Components.interfaces.nsIRequestObserver) &&
!iid.equals(Components.interfaces.nsIStreamListener))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},
onStartRequest: function(aRequest, aContext)
{
// aRequest is your channel... this callback indicates that the upload is starting
},
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount)
{
// for uploads, this function should not be called
},
onStopRequest: function(aRequest, aContext, aStatus)
{
// aRequest is your channel... this callback indicates that the upload has completed.
// it completed successfully if aStatus == 0
}
};
var myStream = Components.classes["@mozilla.org/io/string-input-stream;1"]
.createInstance(Components.interfaces.nsIStringInputStream);
myStream.setData(myData, numberOfBytes);
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var channel = ios.newChannel("ftp://[EMAIL PROTECTED]:host/incoming/foo.xml", null, null);
var uploadChannel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);
uploadChannel.setUploadStream(myStream, "", -1);
channel.asyncOpen(new MyListener(), null);
_______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom
