Android™
Android™
Delete a Remote FTP File (DELE)
See more FTP Examples
Demonstrates the Chilkat Ftp2.DeleteRemoteFile method, which deletes a remote file. The only argument is the remote file path, relative to the current directory or absolute.
Background: Deletion is immediate and permanent — FTP has no trash or undo — so a job that removes files should be certain of the path first. Whether it is allowed depends on the account's permissions on the file and its containing directory. Note that a successful delete does not refresh the cached indexed listing.
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.DeleteRemoteFile method, which deletes a remote file. The only argument
// is the remote file path (relative to the current directory or absolute).
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;
}
success = ftp.ChangeRemoteDir("public_html");
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
success = ftp.DeleteRemoteFile("uploads/obsolete.tmp");
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
Log.i(TAG, "File deleted.");
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."
}
}