Sample code for 30+ languages & platforms
Lua

SFTP Create Directory

See more SFTP Examples

Demonstrates how to create a new directory on the remote SFTP server.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

-- Important: It is helpful to send the contents of the
-- sftp.LastErrorText property when requesting support.

local sftp = chilkat.SFtp.new()

-- Set some timeouts, in milliseconds:
sftp.connect_timeout_ms = 15000
sftp.idle_timeout_ms = 15000

-- Connect to the SSH server.
local success = sftp:connect("sftp.example.com", 22)
if not success then
    print(sftp.last_error_text)
    return
end

-- Authenticate with the SSH server.  Chilkat SFTP supports
-- both password-based authenication as well as public-key
-- authentication.  This example uses password authenication.
success = sftp:authenticate_pw("myLogin", "myPassword")
if not success then
    print(sftp.last_error_text)
    return
end

-- After authenticating, the SFTP subsystem must be initialized:
success = sftp:initialize_sftp()
if not success then
    print(sftp.last_error_text)
    return
end

-- Create a new directory:
success = sftp:create_dir("myNewDir")
if not success then
    print(sftp.last_error_text)
    return
end

print("Success.")