Skip to content

FTP custom commands

Andrew Lambert edited this page Jan 14, 2023 · 17 revisions

Remarks

libcURL can be used to send arbitrary FTP command sequences before and/or after an FTP transfer completes. This can be used to, for example, delete remote files or send server-specific setup or tear-down commands. The general idea is to tell libcURL to perform a headers-only transfer on a FTP directory URL. libcURL will establish the FTP session, CWD into the remote directory specified in the URL, and then execute any custom commands.

Commands are formatted as a linked list of strings which will be passed verbatim to the server. Use the ListPtr class to construct the list:

  Dim lst As New libcURL.ListPtr
  lst.Append("CWD public_html")
  lst.Append("MKD old")
  lst.Append("RNFR index.html")
  lst.Append("RNTO old/index.html")

You then pass the list to EasyHandle.SetOption with option numbers libcURL.Opts.QUOTE, libcURL.Opts.PREQUOTE, or libcURL.Opts.POSTQUOTE.

Examples

FTP delete

This example deletes a file from a FTP server by sending the DELE verb.

  Dim Server As String = "ftp://ftp.example.com/directory/subdirectory/"
  Dim RemoteFile As String = "file.bin"
  Dim curl As New cURLClient
  Dim cmds As New libcURL.ListPtr
  cmds.Append("DELE " + RemoteFile)
  Call curl.SetOption(libcURL.Opts.POSTQUOTE, cmds)
  If Not curl.Head(Server) Then ' HEAD a directory = CWD directory
    MsgBox(libcURL.FormatError(curl.LastError))
  End If

FTP rename

This example renames the remote file by sending the RNFR and RNTO FTP verbs.

  Dim Server As String = "ftp://ftp.example.com/directory/subdirectory/"
  Dim RemoteFile As String = "file.bin"
  Dim NewName As String = "file2.bin"
  Dim curl As New cURLClient
  Dim cmds As New libcURL.ListPtr
  cmds.Append("RNFR " + RemoteFile) ' Rename-From
  cmds.Append("RNTO " + NewName) ' Rename-To
  Call curl.SetOption(libcURL.Opts.POSTQUOTE, cmds)
  If Not curl.Head(Server) Then ' HEAD a directory = CWD directory
    MsgBox(libcURL.FormatError(curl.LastError))
  End If
Clone this wiki locally