Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Download Text File into String VariableDownload a text file directly into a string variable.
#include <CkFtp2.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkFtp2 ftp; ftp.put_Hostname("ftp.someFtpServer.com"); ftp.put_Username("myFtpUserAccount"); ftp.put_Password("myFtpPassword"); // Set other possible settings... // See http://www.cknotes.com/determining-ftp2-connection-settings/ // for more information about FTP connection settings. ftp.put_Passive(true); ftp.put_AuthTls(true); // Connect and login to the FTP server. bool success = ftp.Connect(); if (success != true) { strOut.append(ftp.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Change to the remote directory where the existing file is located. success = ftp.ChangeRemoteDir("junk"); if (success != true) { strOut.append(ftp.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Download the contents of the remote file into a string variable. // Note: By setting the Utf8 property to true, we are telling the ftp object // to return all strings in the utf-8 encoding. The GetRemoteFileTextData method // downloads an ANSI text file. However, because we've set the Utf8 property = true, // it is automatically converted and returned as utf-8. ftp.put_Utf8(true); // The GetRemoteFileTextData method assumes the remote file contains ANSI chars. // To download text files containing non-ANSI text, such as utf-8, call GetRemoteFileTextC // instead. (see below) const char *fileContents = ftp.getRemoteFileTextData("ansiText.txt"); if (ftp.get_LastMethodSuccess() != true) { strOut.append(ftp.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } else { strOut.append(fileContents); strOut.append("\r\n"); } // To download a remote text file containing utf-8 chars, // call GetRemoteFileTextC and pass "utf-8" for the 2nd arg. This tells // Chilkat to interpret the incoming bytes according to the utf-8 character encoding. fileContents = ftp.getRemoteFileTextC("utf8Text.txt","utf-8"); if (ftp.get_LastMethodSuccess() != true) { strOut.append(ftp.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } else { strOut.append(fileContents); strOut.append("\r\n"); } success = ftp.Disconnect(); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.