This is problem - in binary mode i get file size x 2 (UTF8) and
if i do not set DataEncoding correct i don't get correct charset to text files, except english.
Why DataEncoding affect to download/upload process in binary mode.
private static ExFTPConnection fFTPCln = new ExFTPConnection();
public static bool CreateFTP( string Server, string UserName, string Password,
int TimeOut, bool UseProxy, string ProxyAddr, ref string Result)
{
try
{
if (fFTPCln.IsConnected)
{
fFTPCln.Close();
}
fFTPCln.TransferType = FTPTransferType.BINARY;
fFTPCln.ConnectMode = FTPConnectMode.PASV;
fFTPCln.Timeout = TimeOut * 1000;
fFTPCln.LicenseOwner = "MalamSystemsLtd";
fFTPCln.LicenseKey = "***";
fFTPCln.DataEncoding = Encoding.GetEncoding(1255); //Encoding.ASCII;
string[] ProxyProp = ProxyAddr.Split(':');
if (UseProxy)
{
fFTPCln.ProxySettings.ProxyAddress = ProxyProp[0];
fFTPCln.ProxySettings.ProxyPort = Convert.ToInt32(ProxyProp[1]);
}
fFTPCln.Downloaded += new FTPFileTransferEventHandler(ftpFile_Downloaded);
fFTPCln.Uploaded += new FTPFileTransferEventHandler(ftpFile_Uploaded);
fFTPCln.AutoLogin = false;
fFTPCln.ServerAddress = Server;
fFTPCln.UserName = UserName;
fFTPCln.Password = Password;
fFTPCln.Connect();
fFTPCln.Login();
if (fFTPCln.IsConnected)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Result = ex.Message;
return false;
}
}
public static void GetFile(string FileName ,ref int FTPCount, ref int DelCount, ref string Error)
{
String FN, SrcLocFN, StrNum;
string LocFN = string.Empty;
string FnToRename = string.Empty;
int i;
Error = "";
SrcLocFN = LocFN = FN = Path.GetFileName(FileName);
try
{
FnToRename = FN + "~";
fFTPCln.RenameFile(FN, FnToRename);
LocFN = fLocalDirName + LocFN;
byte[] FtpFileArray = fFTPCln.DownloadByteArray(FnToRename);
FileStream file = new FileStream(LocFN, FileMode.Create, FileAccess.Write);
file.Write(FtpFileArray, 0, FtpFileArray.Length);
file.Close();
}
catch (Exception Ex)
{
Error = Ex.Message;
return;
}
FTPCount++;
if (!fDelAfter)
return;
try
{
fFTPCln.DeleteFile(FnToRename);
}
catch (Exception Ex)
{
Error = Ex.Message;
return;
}
DelCount++;
}