Android™
Android™
Set the FTP Transfer Type to Binary
See more FTP Examples
Demonstrates the Chilkat Ftp2.SetTypeBinary method, which sets the FTP representation type to binary (TYPE I) for subsequent transfers. It takes no arguments.
Note: The local paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: Binary mode transfers bytes verbatim and is the correct choice for essentially every file, text included. Chilkat already defaults to binary, so no call is needed to use it — this method exists to switch back explicitly after a prior
SetTypeAscii. The alternative ASCII mode applies line-ending translation that corrupts binary files, so binary is the safe default to keep in place.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// Demonstrates the Ftp2.SetTypeBinary method, which sets the FTP representation type to binary
// (TYPE I) for subsequent transfers. It takes no arguments.
CkFtp2 ftp = new CkFtp2();
ftp.put_Hostname("ftp.example.com");
ftp.put_Username("myFtpLogin");
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ftp.put_Password("myPassword");
success = ftp.Connect();
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
// Binary mode preserves file bytes exactly and is the appropriate choice for nearly all modern
// file types, text included. Chilkat already defaults to binary, so this call is only needed to
// switch back after a prior SetTypeAscii.
success = ftp.SetTypeBinary();
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
success = ftp.GetFile("public_html/archive.zip","qa_output/archive.zip");
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
success = ftp.Disconnect();
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}