Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

//  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).

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat.Ftp2")
if li_rc < 0 then
    destroy loo_Ftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Ftp.Hostname = "ftp.example.com"
loo_Ftp.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.
loo_Ftp.Password = "myPassword"

li_Success = loo_Ftp.Connect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

li_Success = loo_Ftp.ChangeRemoteDir("public_html")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

li_Success = loo_Ftp.DeleteRemoteFile("uploads/obsolete.tmp")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "File deleted."

li_Success = loo_Ftp.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if



destroy loo_Ftp