I'm trying to upload a file to a ftp server with the following code
(modified from mozblog).
function uploadFile()
{
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var url = Components.classes["@mozilla.org/network/standard-url;1"];
fileurl = url.createInstance(Components.interfaces.nsIURL);
fileurl.spec = "file:///home/sco/polom.html";
var srcChannel = ioService.newChannelFromURI(fileurl);
var remoteUrl = url.createInstance(Components.interfaces.nsIURL);
remoteUrl.spec = "ftp://sco:[EMAIL PROTECTED]/downloads/polom.txt";
var ftpChannel = ioService.newChannelFromURI(remoteUrl)
.QueryInterface(Components.interfaces.nsIUploadChannel);
var bufferedStream =
Components.classes["@mozilla.org/network/buffered-input-stream;1"]
.createInstance(Components.interfaces.nsIBufferedInputStream);
bufferedStream.init(srcChannel.open(), srcChannel.contentLength);
ftpChannel.setUploadStream(bufferedStream,null,-1);
ftpChannel.asyncOpen(myListener(), null);
}
Calling that function gives me the following error:
uncaught exception: [Exception... "Component returned failure code: 0x8000ffff
(NS_ERROR_UNEXPECTED) [nsIChannel.open]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)"
location: "JS frame :: uploadPic.js :: uploadFile :: line 15" data: no]
I'm a little lost there, so any help/hint/lead is welcome.
--
Gilles