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

Ruby Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(Ruby) Get FTP File Permissions

Ruby example showing how to retrieve file permissions (via FTP) for each file in a remote directory.

Chilkat Ruby Downloads

Ruby Library for Linux and MAC OS X

require 'chilkat'

ftp = Chilkat::CkFtp2.new()

#  Any string unlocks the component for the 1st 30-days.
success = ftp.UnlockComponent("Anything for 30-day trial")
if (success != true)
    print ftp.lastErrorText() + "\n";
    exit
end

#  Set the various properties to establish the connection.
ftp.put_Hostname("www.myFtpServer.com")
ftp.put_Username("****")
ftp.put_Password("****")

#  If SSL/TLS is required..
#  See http://www.cknotes.com/determining-ftp2-connection-settings/
#  for more information.
ftp.put_AuthTls(true)
ftp.put_PassiveUseHostAddr(true)

#  Connect to the FTP server:
success = ftp.ConnectOnly()
if (success != true)
    print ftp.lastErrorText() + "\n";
    exit
end

#  Authenticate with the FTP server.
success = ftp.LoginAfterConnectOnly()
if (success != true)
    print ftp.lastErrorText() + "\n";
    exit
end

#  To get file permissions in UNIX format, disallow MSLD:
ftp.put_AllowMlsd(false)

#  To get file and sub-directory information, simply
#  loop from 0 to ftp.GetDirCount() - 1
i = 0
n = ftp.GetDirCount()
if (n < 0)
    print ftp.lastErrorText() + "\n";
    exit
end

#  Show the type of permissions information that is available.
#  The two most common types are "mlsd" and "unix".  See the
#  online reference documentation for more information.
if (n > 0)
    print "The permissions format is: " + ftp.getPermType(0) + "\n";
end

while i < n

    #  Display the permissions and filename
    print ftp.getPermissions(i) + " " + ftp.getFilename(i) + "\n";

    i = i + 1
end

#  Assuming MLSD was possible, let's see the file permissions in MLSD format:
ftp.put_AllowMlsd(true)

#  Clear the directory cache so we're forced to re-fetch the directory listing:
ftp.ClearDirCache()

n = ftp.GetDirCount()
if (n < 0)
    print ftp.lastErrorText() + "\n";
    exit
end

#  Show the type of permissions information that is available.
#  The two most common types are "mlsd" and "unix".  See the
#  online reference documentation for more information.
if (n > 0)
    print "----" + "\n";
    print "The permissions format is: " + ftp.getPermType(0) + "\n";
end

i = 0
while i < n

    #  Display the permissions and filename
    print ftp.getPermissions(i) + " " + ftp.getFilename(i) + "\n";

    i = i + 1
end

success = ftp.Disconnect()

 

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