|
AndFTP provides Intents for third party applications. Intents available are:
- Browse FTP server.
- Pick file or folder on FTP server.
- Upload files/folders from SDCard to a FTP server.
- Download files/folders from a FTP server to SDCard.
- Upload images/videos from gallery to a FTP server already setup in AndFTP.
Browse FTP server:
You have to define a FTP server URL:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("ftp://192.168.20.128:21"));
You can add FTP credentials:
intent.putExtra("ftp_username", "anonymous");
//intent.putExtra("ftp_password", "test@test.com");
//intent.putExtra("ftp_keyfile", "/sdcard/rsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");
If credentials are not provided but required then AndFTP will prompt for login and password.
Setup optional FTP preferences:
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftps_mode", "implicit");
//intent.putExtra("ftp_encoding", "UTF-8");
Finally start the Activity:
startActivityForResult(intent, BROWSE_REQUEST);
Nothing returned in onActivityResult method.
|
 |
Pick file or folder on FTP server:
You have to define a FTP server URL:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(Uri.parse("ftp://192.168.20.128:21"));
You can add FTP credentials:
intent.putExtra("ftp_username", "anonymous");
//intent.putExtra("ftp_password", "test@test.com");
//intent.putExtra("ftp_keyfile", "/sdcard/rsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");
If credentials are not provided but required then AndFTP will prompt for login and password.
Setup optional FTP preferences:
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftps_mode", "implicit");
//intent.putExtra("ftp_encoding", "UTF-8");
Finally start the Activity:
startActivityForResult(intent, PICK_REQUEST);
Selected path will be returned in onActivityResult method:
Uri uri = intent.getData();
|
 |
Upload files from SDCard to FTP server:
You have to define a FTP server URL and upload command:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
Uri ftpUri = Uri.parse("ftp://192.168.20.128");
intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
intent.putExtra("command_type", "upload");
You can add FTP credentials:
intent.putExtra("ftp_username", "anonymous");
intent.putExtra("ftp_password", "test@test.com");
//intent.putExtra("ftp_keyfile", "/sdcard/rsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");;
Setup optional FTP preferences:
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftp_resume", "true");
//intent.putExtra("ftp_encoding", "UTF-8");
And define file(s) to upload and optional remote folder:
intent.putExtra("local_file1", "/sdcard/subfolder1/file1.zip");
intent.putExtra("local_file2", "/sdcard/subfolder2/file2.zip");
// Optional initial remote folder (it must exist before upload)
intent.putExtra("remote_folder", "/remotefolder/subfolder");
Finally start the Activity:
startActivityForResult(intent, UPLOAD_FILES_REQUEST);
Transfer info will be returned in onActivityResult method:
String status = intent.getStringExtra("TRANSFERSTATUS");
String files = intent.getStringExtra("TRANSFERAMOUNT");
String size = intent.getStringExtra("TRANSFERSIZE");
String time = intent.getStringExtra("TRANSFERTIME");
|
 |
Upload folder from SDCard to FTP server:
You have to define a FTP server URL and upload command:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
Uri ftpUri = Uri.parse("ftp://192.168.20.128");
intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
intent.putExtra("command_type", "upload");
You can add FTP credentials:
intent.putExtra("ftp_username", "anonymous");
intent.putExtra("ftp_password", "test@test.com");
//intent.putExtra("ftp_keyfile", "/sdcard/rsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");;
Setup optional FTP preferences:
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftp_resume", "true");
//intent.putExtra("ftp_encoding", "UTF-8");
And define folder(s) to upload and optional remote folder:
intent.putExtra("progress_title", "Uploading folder ...");
intent.putExtra("local_file1", "/sdcard/localfolder");
// Optional Initial remote folder (it must exist before upload)
intent.putExtra("remote_folder", "/remotefolder/uploadedfolder");;
Finally start the Activity:
startActivityForResult(intent, UPLOAD_FOLDER_REQUEST);
Transfer info will be returned in onActivityResult method:
String status = intent.getStringExtra("TRANSFERSTATUS");
String files = intent.getStringExtra("TRANSFERAMOUNT");
String size = intent.getStringExtra("TRANSFERSIZE");
String time = intent.getStringExtra("TRANSFERTIME");
|
 |
Download files from FTP server to SDCard:
You have to define a FTP server URL and download command:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
Uri ftpUri = Uri.parse("ftp://192.168.20.128");
intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
intent.putExtra("command_type", "download");
You can add FTP credentials:
intent.putExtra("ftp_username", "anonymous");
intent.putExtra("ftp_password", "test@test.com");
//intent.putExtra("ftp_keyfile", "/sdcard/rsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");;
Setup optional FTP preferences:
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftp_resume", "true");
//intent.putExtra("ftp_encoding", "UTF-8");
And define file(s) to download into a local folder:
intent.putExtra("remote_file1", "/remotefolder/subfolder/file1.zip");
intent.putExtra("remote_file2", "/remotefolder/subfolder/file2.zip");
// Target local folder where files will be downloaded.
intent.putExtra("local_folder", "/sdcard/localfolder");
Finally start the Activity to be closed after transfer:
intent.putExtra("close_ui", "true");
startActivityForResult(intent, DOWNLOAD_FILES_REQUEST);
Transfer status will be returned in onActivityResult method:
String status = intent.getStringExtra("TRANSFERSTATUS");
String files = intent.getStringExtra("TRANSFERAMOUNT");
String size = intent.getStringExtra("TRANSFERSIZE");
String time = intent.getStringExtra("TRANSFERTIME"); |
 |
Download folder from FTP server to SDCard:
You have to define a FTP server URL and download command:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
Uri ftpUri = Uri.parse("ftp://192.168.20.128");
intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
intent.putExtra("command_type", "download");
You can add FTP credentials:
intent.putExtra("ftp_username", "anonymous");
intent.putExtra("ftp_password", "test@test.com");
//intent.putExtra("ftp_keyfile", "/sdcard/rsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");;
Setup optional FTP preferences:
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftp_resume", "true");
//intent.putExtra("ftp_encoding", "UTF-8");
And define folder(s) to download into a local folder:
intent.putExtra("progress_title", "Downloading folder ...");
// Remote folder to download (must not end with /).
intent.putExtra("remote_file1", "/remotefolder/uploadedfolder");
intent.putExtra("local_folder", "/sdcard/downloadedfolder");
Finally start the Activity to transfer:
startActivityForResult(intent, DOWNLOAD_FOLDER_REQUEST);
Transfer status will be returned in onActivityResult method:
String status = intent.getStringExtra("TRANSFERSTATUS");
String files = intent.getStringExtra("TRANSFERAMOUNT");
String size = intent.getStringExtra("TRANSFERSIZE");
String time = intent.getStringExtra("TRANSFERTIME"); |
 |
Share from gallery:
You have to create a SEND Intent with image or video type:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpeg");
Then pass URI of item to share:
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://media/external/images/media/103"));
Finally start the Activity to transfer:
startActivityForResult(intent, SEND_REQUEST);
Transfer status will be returned in onActivityResult method:
String status = intent.getStringExtra("TRANSFERSTATUS");
String files = intent.getStringExtra("TRANSFERAMOUNT");
String size = intent.getStringExtra("TRANSFERSIZE");
String time = intent.getStringExtra("TRANSFERTIME"); |
 |
The following table provides all properties available for AndFTP Intents:
Property |
Description |
Required |
Intent action |
To upload or download use: Intent.ACTION_PICK
To browse remote folder use: Intent.ACTION_VIEW
To share from gallery: Intent.ACTION_SEND |
Yes |
Intent data |
FTP server URI. It must start with ftp://, sftp://, scp:// or ftps:// followed by hostname and port (optional). For instance:
- ftp://yourserver.com:21
- sftp://yourserver.com:22
- scp://yourserver.com:22
- ftps://yourserver.com:21 (for explicit FTPS)
- ftps://yourserver.com:990 (for implicit FTPS)
This parameter also allows selecting an existing AndFTP configuration through:
- alias://myandftpalias
Finally, to share from gallery, it must not be set and gallery item URI must be available in extra bundle as Intent.EXTRA_STREAM property.
|
Yes |
Intent type |
This parameter is required for Intent.ACTION_PICK, use: "vnd.android.cursor.dir/lysesoft.andftp.uri". It is not needed Intent.ACTION_VIEW. For Intent.ACTION_SEND ot must starts with "image/*" or "video/*". |
No |
progress_title |
Title text displayed in progress windows when uploading or downloading. |
No |
ftp_username |
FTP username to login. |
No |
ftp_password |
FTP password to login.
|
No |
ftp_keyfile |
FTP path to key file for key-based authentication. |
No |
ftp_keypass |
FTP key password for key-based authentication. |
No |
ftp_pasv |
This parameter allows enabling activate or passive mode.
- true: Enable passive mode.
- false: Enable active mode.
Default mode is true.
|
No |
ftp_resume |
This parameter allows enabling resume support for transfers.
- true: Enable resume.
- false: Disable resume.
Default is false. |
No |
ftp_encoding |
This parameter allows selecting charset for FTP server. For instance:
- UTF-8
- SHIFT-JIS
- CP1251
- EUC-KR
- BIG5
- GBK
|
No |
ftps_mode |
This parameter allows selecting implicit or explicit mode for FTPS Value could be:
- implicit
- explicit
Default mode is explicit. |
No |
command_type |
This parameter allows selecting transfer type for Intent.ACTION_PICK. Value could be:
- upload
- download |
No |
remote_fileX |
Set of parameters (X=1 to N) to define remote files/folders. For instance:
remote_file1 = /remotefolder/subfolder1/file1.zip
remote_file2 = /remotefolder/subfolder2/file2.zip
remote_file3 = /remotefolder/subfolder3
...
It can used for upload and download
|
No |
local_fileX |
Set of parameters (X=1 to N) to define local files/folders. For instance:
local_file1 = /sdcard/subfolder1/file1.zip
local_file2 = /sdcard/subfolder2/file2.zip
local_file3 = /sdcard/subfolder3
...
It can be used for upload and download. |
No |
local_folder |
This parameter allows defining a local folder. It can used to select a target folder for download. For instance:
local_folder = /sdcard/localfolder |
No |
remote_folder |
This parameter allows defining a remote folder. It can used to select a target folder for upload. For instance:
remote_folder = /remotefolder/uploadedfolder |
No |
ftp_overwrite |
This parameter allows selecting overwrite policy for duplicated files. Value could be:
- overwrite
- skip
- prompt
Default mode is prompt. |
No |
close_ui |
This parameter allows closing AndFTP progress window after transfer with Intent.ACTION_PICK. For instance:
close_ui = true
Notice that underlying FTP connection will be closed as soon as transfer activity is destroyed. |
No |
|
The following table provides all properties available for Intent returned by AndFTP:
Property |
Description |
Always
returned
|
TRANSFERSTATUS |
Report about status of transfer. It could be:
- COMPLETED
- FAILED
- CANCELLED
- UNKNOWN |
Yes |
TRANSFERAMOUNT |
Amount of files transferred. It is returned for completed transfers.
|
No |
TRANSFERSIZE |
Size in bytes of overall transfer. It is returned for completed transfers. |
No |
TRANSFERTIME |
Duration time of overall transfer. |
Yes |
|
Note: If AndFTP is already running then calling an Intent will close all current FTP connections.
|
Download AndFTPClient source code |
V1.0 |
[zip] |
|
AndFTPClient is a sample application demonstrating how to use Intents from thrid party applications. Each button triggers an Intent.
You can download source code to learn how to use such Intents. |
 |
|
|
AndFTP includes some open source libraries under Apache2 license.
|