Sample code for 30+ languages & platforms
PowerBuilder

Rename or Move a Remote FTP File

See more FTP Examples

Demonstrates the Chilkat Ftp2.RenameRemoteFile method, which renames or moves a remote file or directory using the FTP RNFR/RNTO sequence. The first argument is the existing path and the second is the new path.

Background: Rename and move are the same RNFR/RNTO operation: changing only the final path component renames in place, while including directory components in the new path relocates the item within the same server. It is a metadata operation, so even a large file moves instantly — but both paths must be on the same server, and moving onto an existing target may fail depending on the server.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ftp

li_Success = 0

//  Demonstrates the Ftp2.RenameRemoteFile method, which renames or moves a remote file or
//  directory using the FTP RNFR/RNTO sequence.  The 1st argument is the existing path and the 2nd
//  is the new path.

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

//  Rename a file in place.
li_Success = loo_Ftp.RenameRemoteFile("report.pdf","report_final.pdf")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

//  Include directory components in the new path to move the item within the same server.
li_Success = loo_Ftp.RenameRemoteFile("report_final.pdf","archive/report_final.pdf")
if li_Success = 0 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

Write-Debug "Renamed and moved."

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



destroy loo_Ftp