0

This is a solution if you want to control which files will automatically be transferred by ASCII or BINARY without writing control statements for WinSCP in C#, you have to create a new session and on that session

AddRawConfiguration(@"Interface\CopyParam\Masks", ...)

For example:

using (var session = new Session())
{
    var asciiFileMasks = "*.xsl; *.xslt; *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml";
    session.AddRawConfiguration(@"Interface\CopyParam\Masks", asciiFileMasks );//for automatic transfers, this list determines ascii or binary mode

   ///... do your thing
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 2
    You can *ask a question here*, then answer it below. Stack Overflow isn't a blog, it's a Q&A website. –  Jan 15 '20 at 16:20
  • When you are in text mode, ftp replaces the return characters based on the operating system. So if you are going from linux to windows the you need to use text mode. In binary mode no changes are made. So always use binary mode except when you are transferring text between different operating systems. – jdweng Jan 15 '20 at 16:25

1 Answers1

0

Better solution is using TransferOptions.AddRawSettings. Among other it does not need opening a new session:

var options = new TransferOptions();
options.AddRawSettings("Masks", "*.*html; *.htm; *.txt; *.php; *.php3; ...");

And you of course need to enable automatic transfer mode:

options.TransferMode = TransferMode.Automatic;

Then you use your options instance with methods like Session.GetFiles, Session.PutFiles, etc.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992