XferParams
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
namespace Aspera.Transfer
{
public class XferParams
{
[Obsolete("This method is unreliable for connections faster than 10Mbps, please do not set this.")]
public bool autoDetectCapacity;
public string ;
public bool createDirs;
public int datagramSize;
[Obsolete("This method offers only two options (don't encrypt and AES-128), use 'cipher' instead for more options. ")]
public bool encryption;
public Cipher? cipher;
public string localLogDir = "";
public int minimumRateKbps;
public Policy policy;
public bool preserveDates;
public string remoteLogDir = "";
public int retryTimeoutS;
public SymLinkPolicy? symLinkPolicy;
public Resume? resumeCheck;
public string sourceBase = "";
public int targetRateKbps = 10000;
public int tcpPort = 22;
public string token = "";
public int udpPort = 33001;
public string contentProtectionPassphrase;
public bool preCalculateJobSize;
public FileManifestFormat fileManifestFormat;
public string fileManifestPath = "";
[Obsolete("Use removeFileAfterTransfer and/or removeEmptyDirectories")]
public DeleteSource deleteSource;
public bool removeFileAfterTransfer;
public bool removeEmptyDirectories;
public bool skipSpecialFiles;
public bool preserveFileOwnerUID;
public bool preserveFileOwnerGID;
public bool persist;
public OverwritePolicy overwritePolicy;
public int readSize;
public int writeSize;
public JObject ;
public string prePostCommand;
public string alternateConfigFile;
public string partialFileSuffix;
public int? excludeNewerThan;
public int? excludeOlderThan;
public bool saveBeforeOverwriteEnabled;
public string sourceRoot;
public string checkSshFingerprint;
public bool ignoreSshFingerprint;
public bool applyLocalDocroot;
public long multiSessionThreshold;
public bool removeEmptySourceDirectory;
public bool deleteBeforeTransfer;
public int? retransmissionRequestMaxSize;
public List<string> excludePatterns = new List<string>();
public HTTPFallback httpFallback;
public string moveAfterTransferPath;
public string destinationRoot;
public bool preserveAccessTime;
public bool preserveModificationTime;
public bool preserveSourceAccessTime;
public bool preserveCreationTime;
public bool skipDuplicateCheck;
public AclOption? aclOption;
public AclOption? remoteAclOption;
public ExtendedAttributesOption? extendedAttributesOption;
public ExtendedAttributesOption? remoteExtendedAttributesOption;
public bool reportSkippedFiles;
public FileChecksum fileChecksum = FileChecksum.NONE;
protected internal static readonly string DEFAULT_DESTINATION_ROOT = "";
private static readonly string ASPERA_TAG = "aspera";
private static readonly string XFER_ID_TAG = "xfer_id";
private static readonly string XFER_RETRY_TAG = "xfer_retry";
internal string getDestinationRoot()
{
if (!string.IsNullOrEmpty(destinationRoot) && destinationRoot.Trim().Length != 0)
return destinationRoot;
return DEFAULT_DESTINATION_ROOT;
}
protected internal virtual List<string> buildCommand(bool isUpload, Guid xferId, int xferRetry = 0)
{
List<string> list = new List<string>();
if (autoDetectCapacity)
list.Add("-wf");
if (cipher.HasValue) {
switch (cipher) {
case Cipher.NONE:
list.Add("-T");
break;
case Cipher.AES_128:
list.Add("-c");
list.Add("aes128");
break;
case Cipher.AES_192:
list.Add("-c");
list.Add("aes192");
break;
case Cipher.AES_256:
list.Add("-c");
list.Add("aes256");
break;
}
} else if (!encryption) {
list.Add("-T");
}
list.Add("--policy=" + PolicyHelper.getCommandLineOption(policy));
list.Add("-O" + udpPort);
list.Add("-P" + tcpPort);
list.Add("--retry-timeout=" + retryTimeoutS);
if (fileManifestFormat == FileManifestFormat.NONE)
list.Add("--file-manifest=none");
else {
if (fileManifestFormat == FileManifestFormat.TEXT)
list.Add("--file-manifest=text");
if (fileManifestPath != null && fileManifestPath.Length > 0)
list.Add("--file-manifest-path=" + fileManifestPath);
}
list.Add("-l" + targetRateKbps + (autoDetectCapacity ? "%" : ""));
list.Add("-m" + minimumRateKbps + (autoDetectCapacity ? "%" : ""));
if (symLinkPolicy.HasValue) {
list.Add("--symbolic-links");
switch (symLinkPolicy) {
case SymLinkPolicy.FOLLOW:
list.Add("follow");
break;
case SymLinkPolicy.COPY:
list.Add("copy");
break;
case SymLinkPolicy.SKIP:
list.Add("skip");
break;
case SymLinkPolicy.COPY_FORCE:
list.Add("copy+force");
break;
}
}
if (resumeCheck.HasValue) {
list.Add("-k");
switch (resumeCheck) {
case Resume.OFF:
list.Add("0");
break;
case Resume.FILE_ATTRIBUTES:
list.Add("1");
break;
case Resume.SPARSE_CHECKSUM:
list.Add("2");
break;
case Resume.FULL_CHECKSUM:
list.Add("3");
break;
}
}
if (preserveDates)
list.Add("-p");
if (skipSpecialFiles)
list.Add("--skip-special-files");
if (preserveFileOwnerUID)
list.Add("--preserve-file-owner-uid");
if (preserveFileOwnerGID)
list.Add("--preserve-file-owner-gid");
if (datagramSize != 0)
list.Add("-Z" + datagramSize);
if (createDirs)
list.Add("-d");
if (localLogDir.Length > 0) {
list.Add("-L");
list.Add(localLogDir);
}
if (remoteLogDir.Length > 0) {
list.Add("-R");
list.Add(remoteLogDir);
}
JObject jObject = new JObject();
jObject.Add(ASPERA_TAG, createAsperaTags(xferId, xferRetry));
if (tags != null)
jObject.Merge(tags);
list.Add("--tags64");
list.Add(Convert.ToBase64String(Encoding.UTF8.GetBytes(jObject.ToString(Formatting.None))));
if (excludePatterns.Count > 0) {
foreach (string excludePattern in excludePatterns) {
list.Add("-E" + excludePattern);
}
}
if (OverwritePolicy.DIFFERENT_AND_OLDER == overwritePolicy)
list.Add("-o Overwrite=diff,Overwrite=older");
else
list.Add("--overwrite=" + OverwritePolicyHelper.getCommandLineOption(overwritePolicy));
if (contentProtectionPassphrase != null) {
if (isUpload)
list.Add("--file-crypt=encrypt");
else
list.Add("--file-crypt=decrypt");
}
if (sourceBase != null && sourceBase.Trim().Length > 0) {
list.Add("--src-base=");
list.Add(sourceBase);
}
if (readSize > 0)
list.Add("-g " + readSize);
if (writeSize > 0)
list.Add("-G " + writeSize);
if (removeFileAfterTransfer || deleteSource == DeleteSource.FILES_AND_DIRECTORIES || deleteSource == DeleteSource.FILES_ONLY)
list.Add("--remove-after-transfer");
if (removeEmptyDirectories || deleteSource == DeleteSource.EMPTY_DIRECTORIES || deleteSource == DeleteSource.FILES_AND_DIRECTORIES)
list.Add("--remove-empty-directories");
if (preCalculateJobSize)
list.Add("--precalculate-job-size");
if (!string.IsNullOrEmpty(prePostCommand) && prePostCommand.Trim().Length > 0)
list.Add("-e " + prePostCommand);
if (!string.IsNullOrEmpty(alternateConfigFile) && alternateConfigFile.Trim().Length > 0)
list.Add("-f " + alternateConfigFile);
if (!string.IsNullOrEmpty(partialFileSuffix) && partialFileSuffix.Trim().Length > 0)
list.Add("--partial-file-suffix=" + partialFileSuffix);
if (excludeNewerThan.HasValue)
list.Add("--exclude-newer-than=" + excludeNewerThan);
if (excludeOlderThan.HasValue)
list.Add("--exclude-older-than=" + excludeOlderThan);
if (saveBeforeOverwriteEnabled)
list.Add("--save-before-overwrite");
if (!string.IsNullOrEmpty(checkSshFingerprint) && checkSshFingerprint.Trim().Length > 0)
list.Add("--check-sshfp=" + checkSshFingerprint);
if (ignoreSshFingerprint)
list.Add("--ignore-host-key");
if (retransmissionRequestMaxSize.HasValue)
list.Add("-X " + retransmissionRequestMaxSize);
if (httpFallback != null) {
List<string> list2 = httpFallback.buildCommandOptions();
foreach (string item in list2) {
list.Add(item);
}
}
if (moveAfterTransferPath != null)
list.Add("--move-after-transfer=" + moveAfterTransferPath);
if (!string.IsNullOrEmpty(sourceRoot) && sourceRoot.Trim().Length > 0)
list.Add("--source-prefix=" + sourceRoot);
if (applyLocalDocroot)
list.Add("--apply-local-docroot");
if (multiSessionThreshold > 0)
list.Add("--multi-session-threshold=" + multiSessionThreshold);
if (removeEmptySourceDirectory)
list.Add("--remove-empty-source-directory");
if (deleteBeforeTransfer)
list.Add("--delete-before-transfer");
if (aclOption.HasValue) {
switch (aclOption) {
case AclOption.NONE:
list.Add("--preserve-acls=none");
break;
case AclOption.NATIVE:
list.Add("--preserve-acls=native");
break;
case AclOption.METAFILE:
list.Add("--preserve-acls=metafile");
break;
}
}
if (remoteAclOption.HasValue) {
switch (remoteAclOption) {
case AclOption.NONE:
list.Add("--remote-preserve-acls=none");
break;
case AclOption.NATIVE:
list.Add("--remote-preserve-acls=native");
break;
case AclOption.METAFILE:
list.Add("--remote-preserve-acls=metafile");
break;
}
}
if (extendedAttributesOption.HasValue) {
switch (extendedAttributesOption) {
case ExtendedAttributesOption.NONE:
list.Add("--preserve-xattrs=none");
break;
case ExtendedAttributesOption.NATIVE:
list.Add("--preserve-xattrs=native");
break;
case ExtendedAttributesOption.METAFILE:
list.Add("--preserve-xattrs=metafile");
break;
}
}
if (remoteExtendedAttributesOption.HasValue) {
switch (remoteExtendedAttributesOption) {
case ExtendedAttributesOption.NONE:
list.Add("--remote-preserve-xattrs=none");
break;
case ExtendedAttributesOption.NATIVE:
list.Add("--remote-preserve-xattrs=native");
break;
case ExtendedAttributesOption.METAFILE:
list.Add("--remote-preserve-xattrs=metafile");
break;
}
}
if (preserveCreationTime)
list.Add("--preserve-creation-time");
if (preserveModificationTime)
list.Add("--preserve-modification-time");
if (preserveAccessTime)
list.Add("--preserve-access-time");
if (preserveSourceAccessTime)
list.Add("--preserve-source-access-time");
if (skipDuplicateCheck)
list.Add("--skip-dir-traversal-dupes");
if (fileChecksum.ToString().ToLower() != "none")
list.Add("--file-checksum=" + fileChecksum.ToString().ToLower());
List<string> extendedOptions = getExtendedOptions();
if (extendedOptions != null && extendedOptions.Count > 0)
list.AddRange(extendedOptions);
return list;
}
private JObject createAsperaTags(Guid xferId, int xferRetry)
{
JObject jObject = new JObject();
jObject.Add(XFER_ID_TAG, xferId.ToString());
jObject.Add(XFER_RETRY_TAG, xferRetry);
JObject jObject2 = appendToAsperaTags();
if (jObject2 != null)
jObject.Merge(jObject2);
return jObject;
}
protected virtual JObject appendToAsperaTags()
{
return null;
}
protected virtual List<string> getExtendedOptions()
{
return null;
}
protected internal void validate()
{
string text = "";
if (datagramSize < 0)
text = "Invalid datagramSize. Current value is " + datagramSize + ". datagramSize must be positive.";
else if (datagramSize != 0 && (datagramSize < 296 || datagramSize > 10000)) {
text = "Invalid datagramSize. Current value is " + datagramSize + ". datagramSize must be between 296 and 10000.";
} else if (minimumRateKbps < 0) {
text = "Invalid minimumRate. Current value is " + minimumRateKbps + ". minimumRate must be positive.";
} else if (targetRateKbps < 0) {
text = "Invalid targetRate. Current value is " + targetRateKbps + ". targetRate must be positive.";
} else if (targetRateKbps < minimumRateKbps) {
text = "minimumRate (" + minimumRateKbps + ") must be less than targetRate (" + targetRateKbps + ").";
} else if (tcpPort < 1 || tcpPort > 65535) {
text = "Invalid tcpPort value " + tcpPort + ". tcpPort must be between 1 and 65535.";
} else if (udpPort < 1 || udpPort > 65535) {
text = "Invalid udpPort value " + udpPort + ". udpPort must be between 1 and 65535.";
} else if (autoDetectCapacity && (minimumRateKbps > 100 || targetRateKbps > 100)) {
text = "When autoDetectCapacity is turned on, minimumRateKbps and targetRateKbps are interpreted as percentages of measured bandwidth. Specify values less than or equal to 100";
} else if (retryTimeoutS < 0) {
text = "Invalid retryTimeoutS value " + retryTimeoutS + ". retryTimeoutS must be positive.";
} else if (excludePatterns.Count > 16) {
text = "Maximum of 16 path exclusion patterns is allowed. Provided " + excludePatterns.Count + " patterns.";
} else if (tags != null && tags.GetValue("aspera") != null) {
text = "User defined tags cannot use the reserved name \"aspera\"";
}
JObject jObject = appendToAsperaTags();
if (jObject != null) {
if (jObject.GetValue(XFER_ID_TAG) != null)
text = XFER_ID_TAG + " is managed by the FaspManager SDK and cannot be overriden here. Use the appropriate startTransfer() instead.";
else if (jObject.GetValue(XFER_RETRY_TAG) != null) {
text = XFER_RETRY_TAG + " is managed by the FaspManager SDK and cannot be overriden here. Use the appropriate startTransfer() instead.";
}
}
if (text.Length > 0)
throw new FaspManagerException("XferParams Validation failed: " + text);
}
}
}