Android™
Android™
Change the Remote Directory (CWD)
See more FTP Examples
Demonstrates the Chilkat Ftp2.ChangeRemoteDir method, which changes the current working directory on the FTP server. The only argument is the remote directory path.
Background: This sends a single
CWD with the path exactly as given; Chilkat does not split a multi-level path into one CWD per segment, so whether a/b/c works in one call depends on the server. A relative path moves from the current directory, while an absolute path (leading /) is resolved from the root according to the server's conventions. Confirm the result with GetCurrentRemoteDir when it matters.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.ChangeRemoteDir method, which changes the current working directory on
// the FTP server. The only argument is the remote directory path.
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");
// Connect and log in (Connect performs both).
success = ftp.Connect();
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
// A relative path is resolved from the current remote directory; an absolute path (beginning
// with "/") is interpreted according to the server's path syntax.
success = ftp.ChangeRemoteDir("public_html/images");
if (success == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
String currentDir = ftp.getCurrentRemoteDir();
if (ftp.get_LastMethodSuccess() == false) {
Log.i(TAG, ftp.lastErrorText());
return;
}
Log.i(TAG, "Now in: " + currentDir);
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."
}
}