Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PowerBuilder Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) Directory Existence Check

How to test if a directory exists on an FTP server.

A good way to check to see if a directory already exists is to try to "cd" to that remote directory by calling ChangeRemoteDir. If it succeeds, then the directory exists. If not, then it does not exist. An alternative method is to set the ListPattern = "*" and then iterate over the files/directories, looking for the directory.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Ftp
integer li_Success
integer li_DirExists
integer i
integer n
integer li_IsDir
string ls_Fname

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

loo_Ftp = create oleobject
li_rc = loo_Ftp.ConnectToNewObject("Chilkat_9_5_0.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 = "login"
loo_Ftp.Password = "password"

// Connect and login to the FTP server.
li_Success = loo_Ftp.Connect()
if li_Success <> 1 then
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

// Does the "temp" directory exist?

li_DirExists = loo_Ftp.ChangeRemoteDir("/temp")
if li_DirExists = 1 then
    Write-Debug "Yes, the temp directory exists."
    //  Yes, it exists. Restore the current remote dir:
    li_Success = loo_Ftp.ChangeRemoteDir("..")
    if li_Success <> 1 then
        Write-Debug loo_Ftp.LastErrorText
        destroy loo_Ftp
        return
    end if

end if

// Alternatively, you may set the ListPattern = "*" and 
//  look for the directory:
loo_Ftp.ListPattern = "*"

n = loo_Ftp.GetDirCount()
if n < 0 then
    // Failed to get directory listing based on ListPattern
    Write-Debug loo_Ftp.LastErrorText
    destroy loo_Ftp
    return
end if

if n > 0 then
    for i = 0 to n - 1

        li_IsDir = loo_Ftp.GetIsDirectory(i)
        if li_IsDir = 1 then

            ls_Fname = loo_Ftp.GetFilename(i)
            if ls_Fname = "temp" then
                Write-Debug "Found temp directory!"
                li_Success = loo_Ftp.Disconnect()
                destroy loo_Ftp
                return
            end if

        end if

    next
end if

li_Success = loo_Ftp.Disconnect()


destroy loo_Ftp

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.