/* jshint node: true,globals: true */
var JSFtp = require("jsftp");

var jftp = new JSFtp({
  host: "ftp.techus24x7.com",
  port: 21, // defaults to 21
  user: "mayon_test@techus24x7.com", // defaults to "anonymous"
  pass: "Yash121#" // defaults to "@anonymous"
});

var ftp = {}; // better would be to have module create an object
module.exports = ftp;


ftp.test = function() {
  


    api.request('get_data',['ftp','hostname'], function(err, errors, res){
    
        if(err)
        {
            this.error = errors;
            console.log('Err:' + errors); 
        }
        
        
    
        console.log("Result: " + res );
       
        

    });


  jftp.put('/var/www/html/index.html', 'index.html', function(hadError) {
    if (!hadError)
     console.log("Uploading done");
  });
  
  //_this = this;
  
  jftp.ls(".", function(err, res) {
    res.forEach(function(file) {
      console.log(file);
    });
    
    ftp.quit();
    
  });

 };  
 
  ftp.quit = function()  {  
    
    jftp.raw.quit(function(err, data) {
      if (err) return console.error(err);
  
      console.log("Bye!");
  });

};
  /*
  ftp.list(remoteCWD, function(err, res) {
    console.log(res);
    // Prints something like
    // -rw-r--r--   1 sergi    staff           4 Jun 03 09:32 testfile1.txt
    // -rw-r--r--   1 sergi    staff           4 Jun 03 09:31 testfile2.txt
    // -rw-r--r--   1 sergi    staff           0 May 29 13:05 testfile3.txt
    // ...
  });
  */



@@ -413,16 +413,17 @@
 ,%5B'ftp',
+%5B
 'hostnam
@@ -424,16 +424,29 @@
 ostname'
+,'username'%5D 
 %5D, funct
@@ -604,24 +604,24 @@
       %0A    %0A
-
         cons
@@ -645,16 +645,615 @@
 %22 + res 
++ typeof(res) );%0A        console.log(JSON.stringify(res) ) ;%0A        var t = JSON.parse(res) ;%0A        console.log(t.hostname + %22 %7C %22 + t.username);%0A       %0A        %0A%0A    %7D);%0A    %0A    api.request('set_data',%5B'ftp','username', 'Archana is crazy' %5D, function(err, errors, res)%7B%0A    %0A        if(err)%0A        %7B%0A            this.error = errors;%0A            console.log('Err:' + errors); %0A        %7D%0A        %0A        %0A    %0A        console.log(%22Result: %22 + res + typeof(res) );%0A        console.log(JSON.stringify(res) ) ;%0A        var t = JSON.parse(res) ;%0A        console.log(t.hostname + %22 %7C %22 + t.username
 );%0A     

set and get data from Gui Widget