Xbase++
Xbase++
Add Email Attachment from FTP
Downloads (into memory) a file from an FTP server and adds it as an attachment to an email.Note: This example requires Chilkat v9.5.0.63 or later.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oFtp
LOCAL oPdfData
LOCAL oEmail
nSuccess := 0
// Note: This example requires Chilkat v9.5.0.63 or later.
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
oFtp := CreateObject("Chilkat.Ftp2")
oFtp:Hostname := "www.my-ftp-server.com"
oFtp:Username := "mFtpLogin"
oFtp:Password := "myFtpPassword"
// Connect to the FTP server.
nSuccess := oFtp:ConnectOnly()
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// Authenticate with the FTP server.
nSuccess := oFtp:LoginAfterConnectOnly()
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// Move to the remove directory where our file is located.
nSuccess := oFtp:ChangeRemoteDir("qa_data")
IF (nSuccess == 1)
nSuccess := oFtp:ChangeRemoteDir("pdf")
ENDIF
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
RETURN
ENDIF
// Download...
oPdfData := CreateObject("Chilkat.BinData")
nSuccess := oFtp:GetFileBd("fishing.pdf", oPdfData)
IF (nSuccess != 1)
? oFtp:LastErrorText
oFtp:destroy()
oPdfData:destroy()
RETURN
ENDIF
oFtp:Disconnect()
// Create an email object, and add the PDF as an attachment.
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "Test with PDF attachment."
oEmail:Body := "This is a plain-text body.."
// Add the PDF attachment. (This method call requires Chilkat v9.5.0.63 or later)
nSuccess := oEmail:AddAttachmentBd("fishing.pdf", oPdfData, "application/pdf")
IF (nSuccess != 1)
? oEmail:LastErrorText
oFtp:destroy()
oPdfData:destroy()
oEmail:destroy()
RETURN
ENDIF
// Save the email and examine with a text editor to see the PDF attachment is present..
oEmail:SaveEml("qa_output/out.eml")
? "Success."
oFtp:destroy()
oPdfData:destroy()
oEmail:destroy()