Hi, I have a code to upload stuff over ftp. I believe it used to work, 
but now (with mozilla 1.0) it only create a 0 byte file. The 
onStopRequest's request.status popup with something like interface not 
implemented.

Naturally I take a look at editor's publish code, but it seems like they 
  make use of nsIWebBrowserPersist::saveDocument() instead of using the 
nsiuploadchannel. I also tried use PublishCopyFile() in publish.js but 
it seems the line
   ftpChannel.uploadStream = srcChannel.open();
is not correct. Probabily why they don't use it.

Does anyone have any ideas on whats causing the problem. Or better 
still, how to fix it. Code I use is attached below. I did some 
modification, the original code that used to work is at [1] mozdev.

Thanks.

filepath point to the file with uri eg. file:///c:/foo.png
destUrl is a correct ftp uri eg. ftp://192.168.0.1/
ftpUserName is the username
ftpPassword is filled with the correct password

-- code snip --

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 = filepath;
fileurl = fileurl.QueryInterface(Components.interfaces.nsIFileURL);
var fileHandle = fileurl.file;

remoteUrl = url.createInstance(Components.interfaces.nsIURL);
remoteUrl.spec = destUrl;
if (this.ftpUserName) {
   remoteUrl.username = ftpUserName;
   if (this.ftpPassword) {
     remoteUrl.password = ftpPassword;
   }
}

if (remoteUrl.scheme == 'ftp') {
    var channel = ioService.newChannelFromURI(remoteUrl)
                  .QueryInterface(Components.interfaces.nsIFTPChannel);
    var upload = channel.QueryInterface(
                         Components.interfaces.nsIUploadChannel);
    upload.setUploadFile(fileHandle, null, -1);
    channel.asyncOpen(this, null);
} else {
    alert ("Only ftp server is supported");
}

-- end code --

[1] 
http://www.mozdev.org/source/browse/mozblog/src/content/Attic/uploadPic.js?annotate=1.1&hideattic=0

-- 
Mike Lee
Website: http://www.exitspace.net/mike


Reply via email to