public static int GetDefaultPort(FtpEncryptionMode encryption) { return(new FtpClient() { EncryptionMode = encryption }.Port); }
private void ShowFtpDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel) { #if !NoNet AlertDialog.Builder builder = new AlertDialog.Builder(activity); View dlgContents = activity.LayoutInflater.Inflate(Resource.Layout.ftpcredentials, null); builder.SetView(dlgContents); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { string host = dlgContents.FindViewById <EditText>(Resource.Id.ftp_host).Text; string portText = dlgContents.FindViewById <EditText>(Resource.Id.ftp_port).Text; FtpEncryptionMode encryption = (FtpEncryptionMode)dlgContents.FindViewById <Spinner>(Resource.Id.ftp_encryption).SelectedItemPosition; int port = NetFtpFileStorage.GetDefaultPort(encryption); if (!string.IsNullOrEmpty(portText)) { int.TryParse(portText, out port); } string user = dlgContents.FindViewById <EditText>(Resource.Id.ftp_user).Text; string password = dlgContents.FindViewById <EditText>(Resource.Id.ftp_password).Text; string initialPath = dlgContents.FindViewById <EditText>(Resource.Id.ftp_initial_dir).Text; string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a).BuildFullPath(host, port, initialPath, user, password, encryption); onStartBrowse(ftpPath); }); EventHandler <DialogClickEventArgs> evtH = new EventHandler <DialogClickEventArgs>((sender, e) => onCancel()); builder.SetNegativeButton(Android.Resource.String.Cancel, evtH); builder.SetTitle(activity.GetString(Resource.String.enter_ftp_login_title)); Dialog dialog = builder.Create(); dialog.Show(); #endif }
public Site(string name, string hostname, ushort port, NetworkCredential credential, FtpEncryptionMode encryptionMode) { Name = name; Hostname = hostname; Port = port; Credential = credential; EncryptionMode = encryptionMode; }
private void ShowFtpDialog(Activity activity, Util.FileSelectedHandler onStartBrowse, Action onCancel, string defaultPath) { #if !NoNet AlertDialog.Builder builder = new AlertDialog.Builder(activity); View dlgContents = activity.LayoutInflater.Inflate(Resource.Layout.ftpcredentials, null); if (!defaultPath.EndsWith(_schemeSeparator)) { var connection = NetFtpFileStorage.ConnectionSettings.FromIoc(IOConnectionInfo.FromPath(defaultPath)); dlgContents.FindViewById <EditText>(Resource.Id.ftp_user).Text = connection.Username; dlgContents.FindViewById <EditText>(Resource.Id.ftp_password).Text = connection.Password; dlgContents.FindViewById <Spinner>(Resource.Id.ftp_encryption).SetSelection((int)connection.EncryptionMode); var uri = NetFtpFileStorage.IocToUri(IOConnectionInfo.FromPath(defaultPath)); string pathAndQuery = uri.PathAndQuery; var host = uri.Host; var localPath = pathAndQuery; if (!uri.IsDefaultPort) { dlgContents.FindViewById <EditText>(Resource.Id.ftp_port).Text = uri.Port.ToString(); } dlgContents.FindViewById <EditText>(Resource.Id.ftp_host).Text = host; dlgContents.FindViewById <EditText>(Resource.Id.ftp_initial_dir).Text = localPath; } builder.SetView(dlgContents); builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { string host = dlgContents.FindViewById <EditText>(Resource.Id.ftp_host).Text; string portText = dlgContents.FindViewById <EditText>(Resource.Id.ftp_port).Text; FtpEncryptionMode encryption = (FtpEncryptionMode)dlgContents.FindViewById <Spinner>(Resource.Id.ftp_encryption).SelectedItemPosition; int port = NetFtpFileStorage.GetDefaultPort(encryption); if (!string.IsNullOrEmpty(portText)) { int.TryParse(portText, out port); } string user = dlgContents.FindViewById <EditText>(Resource.Id.ftp_user).Text; string password = dlgContents.FindViewById <EditText>(Resource.Id.ftp_password).Text; string initialPath = dlgContents.FindViewById <EditText>(Resource.Id.ftp_initial_dir).Text; string ftpPath = new NetFtpFileStorage(_activity, App.Kp2a).BuildFullPath(host, port, initialPath, user, password, encryption); onStartBrowse(ftpPath); }); EventHandler <DialogClickEventArgs> evtH = new EventHandler <DialogClickEventArgs>((sender, e) => onCancel()); builder.SetNegativeButton(Android.Resource.String.Cancel, evtH); builder.SetTitle(activity.GetString(Resource.String.enter_ftp_login_title)); Dialog dialog = builder.Create(); dialog.Show(); #endif }
public PluginFtps(Task task, string server, int port, string user, string password, string path, EncryptionMode encryptionMode) : base(task, server, port, user, password, path) { switch (encryptionMode) { case EncryptionMode.Explicit: _encryptionMode = FtpEncryptionMode.Explicit; break; case EncryptionMode.Implicit: _encryptionMode = FtpEncryptionMode.Implicit; break; } }
public ProtocolFTPS(string server, int port, string user, string password, string path, EncryptionMode encryptionMode) : base(server, port, user, password, path) { switch (encryptionMode) { case EncryptionMode.Explicit: _encryptionMode = FtpEncryptionMode.Explicit; break; case EncryptionMode.Implicit: _encryptionMode = FtpEncryptionMode.Implicit; break; } }
public static String valueOf(FtpEncryptionMode ftpEncryptionMode, Error error) { switch (ftpEncryptionMode) { case FtpEncryptionMode.IMPLICIT: return("IMPLICIT"); case FtpEncryptionMode.EXPLICIT: return("EXPLICIT"); default: error.setError("EM002", "Unknown encryption mode"); return(""); } }
public FtpsOptions() : base() { this._host = ""; this._port = 21; this._user = ""; this._password = ""; this._forceEncryption = true; this._connectionMode = FtpConnectionMode.PASSIVE; this._encoding = FtpEncoding.BINARY; this._encryptionMode = FtpEncryptionMode.EXPLICIT; this._trustStorePath = ""; this._trustStorePassword = ""; this._protocol = FtpsProtocol.TLS1_2; this._whiteList = null; }
public FTP(Uri target, string password, FtpEncryptionMode mode) { _ftp = new FtpClient { EncryptionMode = mode, Host = target.Host, Port = target.Port, Credentials = new NetworkCredential( target.UserInfo, password ) }; log.InfoFormat("FTP - Connecting to {0}", target); _ftp.Connect(); log.InfoFormat("FTP - Changing dir to {0}", target.LocalPath); _ftp.SetWorkingDirectory(target.LocalPath); }
/// <summary> /// Initialize a new instance/ /// </summary> /// <param name="url">Configured url.</param> /// <param name="options">Configured options. cannot be null.</param> public AlternativeFtpBackend(string url, Dictionary <string, string> options) { _accepAllCertificates = CoreUtility.ParseBoolOption(options, OPTION_ACCEPT_ANY_CERTIFICATE); string certHash; options.TryGetValue(OPTION_ACCEPT_SPECIFIED_CERTIFICATE, out certHash); _validHashes = certHash == null ? null : certHash.Split(new[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries); var u = new Utility.Uri(url); u.RequireHost(); if (!string.IsNullOrEmpty(u.Username)) { _userInfo = new System.Net.NetworkCredential(); _userInfo.UserName = u.Username; if (!string.IsNullOrEmpty(u.Password)) { _userInfo.Password = u.Password; } else if (options.ContainsKey("auth-password")) { _userInfo.Password = options["auth-password"]; } } else { if (options.ContainsKey("auth-username")) { _userInfo = new System.Net.NetworkCredential(); _userInfo.UserName = options["auth-username"]; if (options.ContainsKey("auth-password")) { _userInfo.Password = options["auth-password"]; } } } //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code if (_userInfo != null) { _userInfo.Domain = ""; } _url = u.SetScheme("ftp").SetQuery(null).SetCredentials(null, null).ToString(); _url = Duplicati.Library.Utility.Utility.AppendDirSeparator(_url, "/"); _listVerify = !CoreUtility.ParseBoolOption(options, "disable-upload-verify"); // Process the aftp-data-connection-type option string dataConnectionTypeString; if (!options.TryGetValue(CONFIG_KEY_AFTP_DATA_CONNECTION_TYPE, out dataConnectionTypeString) || string.IsNullOrWhiteSpace(dataConnectionTypeString)) { dataConnectionTypeString = null; } if (dataConnectionTypeString == null || !Enum.TryParse(dataConnectionTypeString, true, out _dataConnectionType)) { _dataConnectionType = DEFAULT_DATA_CONNECTION_TYPE; } // Process the aftp-encryption-mode option string encryptionModeString; if (!options.TryGetValue(CONFIG_KEY_AFTP_ENCRYPTION_MODE, out encryptionModeString) || string.IsNullOrWhiteSpace(encryptionModeString)) { encryptionModeString = null; } if (encryptionModeString == null || !Enum.TryParse(encryptionModeString, true, out _encryptionMode)) { _encryptionMode = DEFAULT_ENCRYPTION_MODE; } // Process the aftp-ssl-protocols option string sslProtocolsString; if (!options.TryGetValue(CONFIG_KEY_AFTP_SSL_PROTOCOLS, out sslProtocolsString) || string.IsNullOrWhiteSpace(sslProtocolsString)) { sslProtocolsString = null; } if (sslProtocolsString == null || !Enum.TryParse(sslProtocolsString, true, out _sslProtocols)) { _sslProtocols = DEFAULT_SSL_PROTOCOLS; } }
public string BuildFullPath(string host, int port, string initialPath, string user, string password, FtpEncryptionMode encryption) { var connectionSettings = new ConnectionSettings() { EncryptionMode = encryption, Username = user, Password = password }; string scheme = "ftp"; string fullPath = scheme + "://" + connectionSettings.ToString() + ConnectionSettings.SettingsPostFix + host; if (port != GetDefaultPort(encryption)) { fullPath += ":" + port; } if (!initialPath.StartsWith("/")) { initialPath = "/" + initialPath; } fullPath += initialPath; return(fullPath); }
private static bool IsConnectedButFtpsFailure(List <FtpEncryptionMode> blacklistedEncryptions, FtpEncryptionMode encryption, bool failedFTPS) { // catch error starting explicit FTPS and don't try any more secure connections if (failedFTPS) { if (encryption == FtpEncryptionMode.Auto || encryption == FtpEncryptionMode.Explicit) { // ban explicit FTPS blacklistedEncryptions.Add(encryption); return(true); } } return(false); }
private static bool IsFtpsFailure(List <FtpEncryptionMode> blacklistedEncryptions, FtpEncryptionMode encryption, Exception ex) { // catch error starting explicit FTPS and don't try any more secure connections if (encryption == FtpEncryptionMode.Auto || encryption == FtpEncryptionMode.Explicit) { if (ex is FtpSecurityNotAvailableException) { // ban explicit FTPS blacklistedEncryptions.Add(encryption); return(true); } } // catch error starting implicit FTPS and don't try any more secure connections if (encryption == FtpEncryptionMode.Implicit) { if ((ex is SocketException && (ex as SocketException).SocketErrorCode == SocketError.ConnectionRefused) || ex is TimeoutException) { // ban implicit FTPS blacklistedEncryptions.Add(encryption); return(true); } } return(false); }
/// <summary> /// Initialize a new instance/ /// </summary> /// <param name="url">Configured url.</param> /// <param name="options">Configured options. cannot be null.</param> public AlternativeFtpBackend(string url, Dictionary<string, string> options) { _accepAllCertificates = CoreUtility.ParseBoolOption(options, OPTION_ACCEPT_ANY_CERTIFICATE); string certHash; options.TryGetValue(OPTION_ACCEPT_SPECIFIED_CERTIFICATE, out certHash); _validHashes = certHash == null ? null : certHash.Split(new[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries); var u = new Utility.Uri(url); u.RequireHost(); if (!string.IsNullOrEmpty(u.Username)) { _userInfo = new System.Net.NetworkCredential(); _userInfo.UserName = u.Username; if (!string.IsNullOrEmpty(u.Password)) _userInfo.Password = u.Password; else if (options.ContainsKey("auth-password")) _userInfo.Password = options["auth-password"]; } else { if (options.ContainsKey("auth-username")) { _userInfo = new System.Net.NetworkCredential(); _userInfo.UserName = options["auth-username"]; if (options.ContainsKey("auth-password")) _userInfo.Password = options["auth-password"]; } } //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code if (_userInfo != null) _userInfo.Domain = ""; _url = u.SetScheme("ftp").SetQuery(null).SetCredentials(null, null).ToString(); if (!_url.EndsWith("/")) { _url += "/"; } _listVerify = !CoreUtility.ParseBoolOption(options, "disable-upload-verify"); // Process the aftp-data-connection-type option string dataConnectionTypeString; if (!options.TryGetValue(CONFIG_KEY_AFTP_DATA_CONNECTION_TYPE, out dataConnectionTypeString) || string.IsNullOrWhiteSpace(dataConnectionTypeString)) { dataConnectionTypeString = null; } if (dataConnectionTypeString == null || !Enum.TryParse(dataConnectionTypeString, true, out _dataConnectionType)) { _dataConnectionType = DEFAULT_DATA_CONNECTION_TYPE; } // Process the aftp-encryption-mode option string encryptionModeString; if (!options.TryGetValue(CONFIG_KEY_AFTP_ENCRYPTION_MODE, out encryptionModeString) || string.IsNullOrWhiteSpace(encryptionModeString)) { encryptionModeString = null; } if (encryptionModeString == null || !Enum.TryParse(encryptionModeString, true, out _encryptionMode)) { _encryptionMode = DEFAULT_ENCRYPTION_MODE; } // Process the aftp-ssl-protocols option string sslProtocolsString; if (!options.TryGetValue(CONFIG_KEY_AFTP_SSL_PROTOCOLS, out sslProtocolsString) || string.IsNullOrWhiteSpace(sslProtocolsString)) { sslProtocolsString = null; } if (sslProtocolsString == null || !Enum.TryParse(sslProtocolsString, true, out _sslProtocols)) { _sslProtocols = DEFAULT_SSL_PROTOCOLS; } }