Sample code for 30+ languages & platforms
JavaScript

Delete Remote File

See more FTP Examples

Delete a remote file.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

var ftp = new CkFtp2();

ftp.Hostname = "ftp.chilkatsoft.com";
ftp.Username = "myLogin";
ftp.Password = "myPassword";

// Connect and login to the FTP server.
success = ftp.Connect();
if (success !== true) {
    console.log(ftp.LastErrorText);
    return;
}

// Set the current remote directory to where the file
// is located:
success = ftp.ChangeRemoteDir("/testing");
if (success !== true) {
    console.log(ftp.LastErrorText);
    return;
}

success = ftp.DeleteRemoteFile("goodbye.txt");
if (success !== true) {
    console.log(ftp.LastErrorText);
    return;
}

success = ftp.Disconnect();