Chilkat2-Python
Chilkat2-Python
Get Filenames in a Remote Directory
Gets the names of files in a remote FTP directory.Chilkat Chilkat2-Python Downloads
import sys
import chilkat2
success = False
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
ftp = chilkat2.Ftp2()
ftp.Hostname = "ftp.example.com"
ftp.Username = "myLogin"
ftp.Password = "myPassword"
# Use explicit TLS
ftp.AuthTls = True
ftp.Port = 21
# Connect and login to the FTP server.
success = ftp.Connect()
if (success != True):
print(ftp.LastErrorText)
sys.exit()
# Iterate over .txt files.
ftp.ListPattern = "*.txt"
n = ftp.GetDirCount()
print("n = " + str(n))
i = 0
while i < n :
print(str(i) + ": " + ftp.GetFilename(i))
i = i + 1