Code Monkey home page Code Monkey logo

appwerft.ti.ftp4j's Introduction

#Ti.Ftp4j

This is the Titanium version of FTP client ftp4j

The ftp4j library implements a Java full-features FTP client. With ftp4j embedded in your application you can: transfer files (upload and download), browse the remote FTP site (directory listing included), create, delete, rename and move remote directories and files.

A pure JS implementaion you can find in Kosso's gist

##Usage

###Download

var FTP = require("de.appwerft.ftp4j");
var client = FTP.createDownload({
	url : "ftp://gds32025:cE***[email protected]:21/gds/specials/radar/Radarfilm_WEB_DL.gif",
	/* you use file or filename (nativePath) */
	file : Ti.Filesystem.getFile( Ti.Filesystem.applicationCacheDirectory,"rainradar.gif");
	keepalive : false, // autodisconenct after download 
	onload : function(e) {
		console.log(e);
	},
	onerror: function(e) {
		console.log(e);
	},
	onprogress: function(e) {
		console.log(e);
	}
});

If the URL is a path (without file) you will get a list of file names. If you request a full path with file you will get additional the file as Blob.

###Upload

var FTP = require("de.appwerft.ftp4j");
var client = FTP.createUpload({
	url : "ftp://gds32025:[email protected]:21/gds/specials/radar/Radarfilm_WEB_DL.gif",
	file : Ti.Filesystem.getFile( Ti.Filesystem.applicationCacheDirectory,"rainradar.gif");
	keepalive : false, // autodisconenct after download 
	onload : function(e) {
		console.log(e);
	},
	onerror: function(e) {
		console.log(e);
	},
	onprogress: function(e) {
		console.log(e);
	}
});

If the URL is a path (without file) you will get a list of file names. If you request a full path with file you will get additional the file as Blob.

###Browsing the remote site

Change directory with:

client.changeDirectory(newPath);

Back to the parent directory with:

client.changeDirectoryUp();

###Listing files, directories and links

The FTP protocol doesn't offer a wide supported method to get complete informations about the contents of the working directory. The LIST command usually gives all you need to know, but unfortunately every server can use a different style for the response. It means that some servers return a UNIX style directory listing, some servers prefer the DOS style, others use some alternative ones.

The ftp4j library can handle many LIST response formats, building from them a unified structured object representation of the directory contents. Currently ftp4j can handle:

UNIX style and variants (i.e. MAC style)
DOS style
NetWare styles
EPLF
MLSD

This is done using pluggable parsers. The package it.sauronsoftware.ftp4j.listparsers contains the ones handling the styles listed above. Most of the time this should be enough.

To list the current working directory entries call:

var list = client.list();
list.forEach(function(file){
	console.log(file); // object with name, ctime, size etc.
});

Only the names (more stable)

var list = client.listNames();
list.forEach(function(file){
	console.log(file); 
});

###Download

appwerft.ti.ftp4j's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.