-
-
Notifications
You must be signed in to change notification settings - Fork 11
FTP custom commands
##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
Call lst.Append("CWD public_html")
Call lst.Append("MKD old")
Call lst.Append("RNFR index.html")
Call 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. This is accomplished by telling libcURL to do a directory listing of the remote parent directory (URL path ends in a /
indicating a directory; NOBODY
is True) and sending custom FTP commands after the transfer finishes (i.e. the commands specified by POSTQUOTE
).
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
Call 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
Call cmds.Append("RNFR " + RemoteFile) ' Rename-From
Call 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
Wiki home | Project page | Bugs | Become a sponsor
Text and code examples are Copyright ©2014-24 Andrew Lambert, offered under the CC BY-SA 3.0 License.