public Response <FtpConfig> AddFtpConfig(FtpConfig ftpConfig, TokenCheckInfo tokenCheckInfo) { try { TokenRequest <FtpConfig> requestValue = new TokenRequest <FtpConfig>() { RequestData = ftpConfig, Token = tokenCheckInfo.Token, UserId = tokenCheckInfo.UserId, Version = tokenCheckInfo.Version }; string requestUri = this.baseAddr + @"api/ftpconfig/AddFtpConfig"; HttpResponseMessage responseMessage = HttpClientHelper.Client.PostAsJsonAsync <TokenRequest <FtpConfig> >(requestUri, requestValue).Result; if (responseMessage.IsSuccessStatusCode) { return(responseMessage.Content.ReadAsAsync <Response <FtpConfig> >().Result); } else { LogHelper.WriteLog(LogType.Error, "FtpConfigManager", "AddFtpConfig", "HTTP响应失败:" + requestUri); return(null); } } catch (Exception ex) { LogHelper.WriteLog(LogType.Error, ex); return(null); } }
public VirtualFileSystem(FtpConfig config, FtpUserGroup group, string rootpath = null) { _config = config; _group = group; if (!string.IsNullOrEmpty(rootpath)) { _rootPath = rootpath; } else if (!string.IsNullOrEmpty(group.HomeDir)) { _rootPath = group.HomeDir; } else { _rootPath = config.HomeDir; } _rootDirectory = new VDirectory(null, new FilePermission("r-xr-xr-x"), _rootPath, ""); _currentDirectory = _rootDirectory; _currentDirectory.Refresh(); AddGroupLinks(); //FIXED:应在刷新后加入链接 _currentDirectory.Refresh(); SetPermission(_currentDirectory, true); }
private void DeleteFtpFiles(FtpConfig ftpConfig) { Nlog.Info(ftpConfig.FileType, $"{ftpConfig.FileType}\t开始删除..."); var ftp = Containers.Resolve <IFtp>( new NamedParameter("nLogName", ftpConfig.FileType), new NamedParameter("ftpServerIp", ftpConfig.Ip), new NamedParameter("ftpProt", ftpConfig.Port), new NamedParameter("privateKeyFile", Path.Combine(Environment.CurrentDirectory, @"SFTP_KEY\tmp.cap")), new NamedParameter("ftpRemotePath", ftpConfig.RemoteFolder), new NamedParameter("ftpUserId", ftpConfig.Uid), new NamedParameter("ftpPassword", ftpConfig.Pwd), new NamedParameter("isdirectory", ftpConfig.IsDirectory)); ftp.InitializeFileListStyle(); //Thread.Sleep(5000); var list1 = ftp.FindFiles().Where(x => ftpConfig.NameContains.Length <= 0 || x.Name.ToLower().Contains(ftpConfig.NameContains.ToLower())); Thread.Sleep(3000); var list2 = ftp.FindFiles(); var list = list1.Join(list2, x => new { x.Name, x.Size }, y => new { y.Name, y.Size }, (x, y) => new FileStruct { IsDirectory = x.IsDirectory, Name = x.Name, CreateTime = x.CreateTime, FullName = x.FullName, Size = x.Size, IsSuccess = false }) .Where(x => x.IsDirectory == ftpConfig.IsDirectory).ToList(); foreach (var file in list) { ftp.Delete(file.FullName); } }
public async Task <FtpClientResponse> FtpReadAsync(FtpConfig config, CancellationToken cancellationToken) { Func <string, Task <string> > myFunc = ConfigKeyVault.GetSecureSecret; FtpClientResponse response = new FtpClientResponse { ErrorMessage = "", Status = "", FileData = new List <FtpClientResponseFile>() }; try { if (!string.IsNullOrEmpty(config.AzureBlobStorage.StorageAccountName)) { Func <string, string, string, MemoryStream, string, string, bool> copyFileFunc = FtpStorage.CopyFile; // Retry the following call according to the policy - X times. response = await ActorFtpClient.ReadAsync(config, myFunc, copyFileFunc); } else { Func <string, string, string, MemoryStream, bool> copyFileFunc = FtpStorage.CopyFile; response = await ActorFtpClient.ReadAsync(config, myFunc, copyFileFunc); } } catch (Exception e) { await ActorFtpClient.Stop(); Logger.LogError(e, $"[FtpReadAsync] Failed to create FTP Client: " + e.Message); } return(response); }
/// <summary> /// 获取XDBFtp访问类 /// </summary> /// <returns>FtpAccess对象</returns> public FtpAccess GetXDBFtpAccess() { if (this.m_XDBFtpAccess != null) { return(this.m_XDBFtpAccess); } if (this.m_ConfigAccess == null) { this.m_ConfigAccess = new ConfigAccess(); } FtpConfig ftpConfig = null; short shRet = this.m_ConfigAccess.GetXDBFtpParams(ref ftpConfig); if (shRet != SystemData.ReturnValue.OK) { return(null); } if (ftpConfig == null) { return(null); } this.m_XDBFtpAccess = new FtpAccess(); this.m_XDBFtpAccess.FtpIP = ftpConfig.FtpIP; this.m_XDBFtpAccess.FtpPort = ftpConfig.FtpPort; this.m_XDBFtpAccess.UserName = ftpConfig.FtpUser; this.m_XDBFtpAccess.Password = ftpConfig.FtpPwd; this.m_XDBFtpAccess.FtpMode = ftpConfig.FtpMode; return(this.m_XDBFtpAccess); }
/// <summary> /// FTP下载 /// </summary> /// <param name="ftpConfig">ftp配置</param> /// <param name="ftpEncryption"></param> /// <param name="ignoreCertificateErrors"></param> /// <returns></returns> public static async Task <bool> Download(FtpConfig ftpConfig, FtpEncryption ftpEncryption = FtpEncryption.Implicit, bool ignoreCertificateErrors = true) { using (var ftpClient = new FtpClient(new FtpClientConfiguration { Host = ftpConfig.Host, Port = ftpConfig.Port, Username = ftpConfig.UserName, Password = ftpConfig.Password, BaseDirectory = ftpConfig.BaseDirectory, EncryptionType = ftpEncryption, IgnoreCertificateErrors = true })) { await ftpClient.LoginAsync(); if (string.IsNullOrWhiteSpace(ftpConfig.RemotePath)) { //文件路径为空,递归保存工作目录下的全部文件 await SaveFileAsync(ftpClient, ftpConfig); } else { //文件路径不为空,只保存这一个文件 var localPath = await GetLocalPathAsync(ftpConfig); using (var ftpReadStream = await ftpClient.OpenFileReadStreamAsync(ftpConfig.RemotePath)) await SaveFileAsync(ftpReadStream, localPath, ftpConfig.RenameFormat); } } return(true); }
private void dgvleft_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { //过滤双击列表头弹出窗体 if (e.RowIndex != -1) { if (this.dgvleft.SelectedRows.Count > 0) { //存在选中行 DataGridViewRow dgvr = this.dgvleft.SelectedRows[0]; dgvleft.Tag = dgvr.Index; this.txtid.Text = dgvr.Cells["编号"].Value.ToString(); this.txbusname.Text = dgvr.Cells["业务名称"].Value.ToString(); FtpConfig ftpconfig = executedal.GetFtpConfigList(this.txtid.Text); if (ftpconfig != null && ftpconfig.Configid > 0) { txtftpurl.Text = ftpconfig.FtpUrl.ToString(); if (ftpconfig.FileUrl != "" && ftpconfig.FileUrl != null) { txtfileurl.Text = ftpconfig.FileUrl.ToString(); } else { txtfileurl.Text = ""; } txtusername.Text = ftpconfig.FtpUser.ToString(); txtpwd.Text = ftpconfig.FtpPassWord.ToString(); if (ftpconfig.Enabled == "0") { cbEnabled.Checked = true; } else { cbEnabled.Checked = false; } this.btnSave.Text = "更新"; } else { txtftpurl.Text = ""; txtfileurl.Text = ""; txtusername.Text = ""; txtpwd.Text = ""; cbEnabled.Checked = true; this.btnSave.Text = "保存"; } } else { MessageBox.Show("请选择要设置的数据!"); } } }
public FtpConfig AddFtpConfig(FtpConfig ftpConfig) { FtpConfigEntity entity = ftpConfig.ToEntity(); this.dbContext.FtpConfigs.Add(entity); this.dbContext.SaveChanges(); return(entity.ToModel()); }
public IFtpClientConnection Create(FtpConfig ftpConfig) { EnsureArg.IsNotNull(ftpConfig); EnsureArg.IsNotNull(ftpConfig.Uri); EnsureArg.IsNotNull(ftpConfig.Credentials); return(new FluentFtpClientConnection(ftpConfig)); }
public HostTracking(FtpConfig config, Host host) { Guard.NotNull(() => config, config); Guard.NotNull(() => host, host); Config = config; Host = host; LastScanned = null; }
public IFtpClientPool Create(int maxPoolSize, FtpConfig ftpConfig) { EnsureArg.IsNotNull(ftpConfig); EnsureArg.IsNotNull(ftpConfig.Uri); EnsureArg.IsNotNull(ftpConfig.Credentials); return(new FtpClientPoolArxOne(maxPoolSize, ftpConfig)); }
/// <summary> /// 构造函数 /// </summary> /// <param name="pConfigFile">配置文件</param> /// <param name="pControlHandel">控件句柄</param> public VideoController(string pConfigFile) { //读取配置 ConfigReader cfgReader = new ConfigReader(pConfigFile); _curPhotoConfig = ConfigReader.ReadPhotoConfig(); _curVideoConfig = ConfigReader.ReadVideoConfig();; _controlHandelList = null; }
public FtpClient() { WriteLog += (x) => { }; FtpConfig ftpcon = new FtpConfig(); strFTPIP = ftpcon.IP + ":" + ftpcon.Port; strFTPUser = ftpcon.LoginName; strFTPPSW = ftpcon.Password; }
public FtpConfigVm() { FtpConfig config = new FtpConfig(); this.Address = config.FtpUri; this.UserName = config.FtpUser; this.Pwd = config.FtpPwd; this.SaveConfigCmd = new DelegateCommand(SaveConfig); }
private void _init(IFtpClientProxyConfig config, string host, FtpConfig ftpConfig) { this._config = config; this.Host = host; this.Uri = ftpConfig.Uri; this.Credentials = ftpConfig.Credentials; this.FtpConfig = ftpConfig; }
/// <summary> /// 获取配置字典表中FTP服务器的访问参数 /// </summary> /// <param name="ftpConfig">IP地址</param> /// <returns>SystemData.ReturnValue</returns> public short GetDocFtpParams(ref FtpConfig ftpConfig) { List <ConfigInfo> lstConfigInfos = null; short shRet = this.GetConfigData(SystemData.ConfigKey.DOC_FTP, null, ref lstConfigInfos); ftpConfig = new FtpConfig(); if (lstConfigInfos == null || lstConfigInfos.Count <= 0) { return(shRet); } for (int index = 0; index < lstConfigInfos.Count; index++) { ConfigInfo configInfo = lstConfigInfos[index]; if (GlobalMethods.Misc.IsEmptyString(configInfo.ConfigName)) { continue; } if (GlobalMethods.Misc.IsEmptyString(configInfo.ConfigValue)) { configInfo.ConfigValue = string.Empty; } configInfo.ConfigName = configInfo.ConfigName.Trim().ToUpper(); if (configInfo.ConfigName.Equals(SystemData.ConfigKey.FTP_IP)) { ftpConfig.FtpIP = configInfo.ConfigValue; } else if (configInfo.ConfigName.Equals(SystemData.ConfigKey.FTP_PORT)) { int nPort = 0; if (int.TryParse(configInfo.ConfigValue, out nPort)) { ftpConfig.FtpPort = nPort; } } else if (configInfo.ConfigName.Equals(SystemData.ConfigKey.FTP_USER)) { ftpConfig.FtpUser = configInfo.ConfigValue; } else if (configInfo.ConfigName.Equals(SystemData.ConfigKey.FTP_PWD)) { ftpConfig.FtpPwd = configInfo.ConfigValue; } else if (configInfo.ConfigName.Equals(SystemData.ConfigKey.FTP_MODE)) { if (configInfo.ConfigValue == "1") { ftpConfig.FtpMode = FtpMode.PORT; } } } return(SystemData.ReturnValue.OK); }
/// <summary> /// 构造函数 /// </summary> /// <param name="pCameraCfg">摄像头配置</param> /// <param name="pControlHandel">预览视频控件的句柄</param> /// <param name="pDrawStr">视频上要叠加的字符串</param> public CameraControl(FtpConfig pPhotoConfig, Camera pCameraCfg, IntPtr?pControlHandel) { _curPhotoConfig = pPhotoConfig; _cameraCfg = pCameraCfg; _controlHandel = pControlHandel; _drawStr = ""; // _drawStr = "123456kg"; DarwString = new CHCNetSDK.DRAWFUN(cbDrawFun); m_voice = new CHCNetSDK.VOICEDATACALLBACKV30(Voice); }
/// <summary> /// Initializes a new instance of the <see cref="FtpStorageProvider"/> class. /// </summary> /// <param name="ftpConfig">配置信息.</param> public FtpStorageProvider(FtpConfig ftpConfig) { this.cfg = ftpConfig; if (string.IsNullOrEmpty(this.cfg.LocalRootPath)) { this.cfg.LocalRootPath = AppDomain.CurrentDomain.BaseDirectory; } this.GetFtpClient(); }
public int Update(FtpConfig model) { int resust = 0; StringBuilder strSql = new StringBuilder(); strSql.Append(" update DDI_FtpConfig SET FtpUser='******',FtpPassWord='******',FtpUrl='" + model.FtpUrl + "',FileUrl='" + model.FileUrl + "',Enabled='" + model.Enabled + "' where Configid=" + model.Configid); resust = DbHelperSQL.ExecuteSql(strSql.ToString()); return(resust); }
internal FtpClientProxy(IFtpClientProxyConfig config, IFlurlClientFactory client, TokenProvider tokenProvider, Uri uri, NetworkCredential credentials) { //In here we can dispose the FtpConfig because has no 'Certificate' using var ftpConfig = new FtpConfig(uri, credentials); _init(config, null, ftpConfig); _tokenProvider = tokenProvider; _client = _initClient(client); _connectionInfo = _initConnectionInfo(); }
public int Add(FtpConfig model) { int resust = 0; StringBuilder strSql = new StringBuilder(); strSql.Append(" INSERT INTO DDI_FtpConfig (Configid,FtpUser,FtpPassWord,FtpUrl,FileUrl,Enabled) VALUES (" + model.Configid + ",'" + model.FtpUser.Trim() + "', '" + model.FtpPassWord.Trim() + "','" + model.FtpUrl + "', '" + model.FileUrl + "','" + model.Enabled + "')"); resust = DbHelperSQL.ExecuteSql(strSql.ToString()); return(resust); }
public void SaveConfig() { if (this.address == null || this.address.Trim().Equals(string.Empty)) { this.ConfigHint = "FTP地址不能为空!"; } else { this.ConfigHint = "保存成功!"; FtpConfig config = new FtpConfig(); config.FtpUri = this.address; config.FtpUser = this.userName; config.FtpPwd = this.pwd; } }
public static FtpConfigEntity ToEntity(this FtpConfig ftpConfig) { return(new FtpConfigEntity() { Id = ftpConfig.Id, Name = ftpConfig.Name, Description = ftpConfig.Description, IP = ftpConfig.IP, Port = ftpConfig.Port, IsNeedAuthentication = ftpConfig.IsNeedAuthentication, VirticalDir = ftpConfig.VirticalDir, UserName = ftpConfig.UserName, Password = ftpConfig.Password }); }
/// <summary> /// FTP下载 /// </summary> /// <param name="ip">ftp服务主机ip</param> /// <param name="username">ftp用户名</param> /// <param name="password">ftp用户密码</param> /// <param name="baseDirectory">基础目录</param> /// <param name="remotepath">文件路径</param> /// <param name="localDirectory">本地保存目录</param> /// <param name="port">端口号,默认21</param> /// <param name="ftpEncryption"></param> /// <param name="ignoreCertificateErrors"></param> /// <returns></returns> public static async Task <bool> Download(string ip, string username, string password, string baseDirectory, string remotepath, string localDirectory, int port = 21, FtpEncryption ftpEncryption = FtpEncryption.Implicit, bool ignoreCertificateErrors = true) { var ftpConfig = new FtpConfig { Host = ip, Port = port, UserName = username, Password = password, BaseDirectory = baseDirectory, RemotePath = remotepath, LocalDirectory = localDirectory }; return(await Download(ftpConfig, ftpEncryption, ignoreCertificateErrors)); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Loaded(object sender, RoutedEventArgs e) { //获取称点编码 _curClientCode = XpathHelper.GetValue(_sysConfigFile, _curClientCode); this.notifyIcon = new NotifyIcon(); //this.notifyIcon.BalloonTipText = "文件同步程序"; //设置程序启动时显示的文本 //this.notifyIcon.Text = "文件同步程序";//最小化到托盘时,鼠标点击时显示的文本 this.notifyIcon.BalloonTipText = ""; //设置程序启动时显示的文本 this.notifyIcon.Text = ""; //最小化到托盘时,鼠标点击时显示的文本 this.notifyIcon.Icon = Properties.Resources.FileSync; this.notifyIcon.Visible = true; //退出菜单项 System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出"); exit.Click += new EventHandler(Quit); //关联托盘控件 System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { exit }; notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen); // notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick; //this.notifyIcon.ShowBalloonTip(1000); log.Info("注册托盘图标完成"); //读取照片配置 ConfigReader rf = new ConfigReader(_sysConfigFile); _curPhotoConfig = ConfigReader.ReadPhotoConfig(); log.Info("读取配置文件完成"); _curFtpServices = new FtpManager(); _curFtpServices.FtpUpDown(_curPhotoConfig.FtpIp, _curPhotoConfig.FtpUserName, _curPhotoConfig.FtpPassWord); log.Info("初始化文件服务器完成"); //定时器相关 curUploadTimer = new DispatcherTimer(); curUploadTimer.Interval = new TimeSpan(0, 1, 0); //一分钟检测一次 curUploadTimer.Tick += curUploadJpgTimer_Tick; curUploadTimer.Start(); ShowUpLoadInfo("开始文件同步"); WindowState = System.Windows.WindowState.Minimized; wsl = WindowState; // this.Visibility = System.Windows.Visibility.Hidden; this.Hide(); }
private void BtnUploadFtp_Click(object sender, EventArgs e) { try { var updateFiles = bindingSource.DataSource as List <UpdateFileInfo>; if (updateFiles.Count == 0) { MessageBox.Show("没有需要上传的文件"); return; } txtLog.Clear(); var task = Task.Factory.StartNew(() => { try { synchronizationContext.Post(UpdateLog, "开始上传文件到FTP..."); var ftpHelper = new FtpHelper(FtpConfig.FromConfiguration()); var tempFolder = DateTime.Now.ToString("yyyyMMddHHmm"); foreach (var file in updateFiles) { var remotePath = Path.Combine(ftpHelper.FtpRootPath, tempFolder, file.RelativePath); ftpHelper.Client.UploadFile(file.FilePath, remotePath, FluentFTP.FtpExists.Overwrite, true); file.FtpPath = remotePath; synchronizationContext.Post(UpdateLog, $"上传文件 {file.RelativePath} 成功!"); } } catch (Exception err) { synchronizationContext.Post(UpdateLog, "上传文件异常:" + err.StackTrace); } }); task.ContinueWith((t) => { synchronizationContext.Post(UpdateLog, "上传完成..."); }); } catch (Exception ex) { MessageBox.Show("上传文件到FTP异常:" + ex.Message); } }
/// <summary> /// 处理对象形式参数 /// create by xingbo 19/05/27 /// </summary> /// <param name="valType">目标值type</param> /// <param name="value">值</param> /// <param name="key">涉及到对象时,key</param> private void ProcessingValue(Type valType, object value, string key = null) { if (valType == typeof(FtpBaseConfig)) { FtpConfig.Add(key, (FtpBaseConfig)value); } else if (valType == typeof(UploadBaseConfig)) { LocalConfig = (UploadBaseConfig)value; } else if (valType == typeof(UploadFileBaseConfig)) { FileConfig.Add(key, (UploadFileBaseConfig)value); } else if (valType == typeof(EfConfig)) { EfConfig = (EfConfig)value; } }
private void btnInstance_Click(object sender, EventArgs e) { if (!CheckInput()) { MessageBox.Show("参数错误。未能创建服务器!"); return; } try { FtpConfig config = new FtpConfig(txtDir.Text, txtName.Text, chkAnonymous.Checked, "UniFTP", "UniFTP", _welcome, _logIn, _logOut, GetCounterType()); FtpServer f; if (cboAddress.SelectedItem.ToString() != "Any") { f = new FtpServer(IPAddress.Parse(cboAddress.SelectedItem.ToString()), int.Parse(txtPort.Text), chkV6.Checked, chkV6.Checked ? int.Parse(txtV6Port.Text) : -1); f.Config = config; } else { f = new FtpServer(int.Parse(txtPort.Text), config, chkV6.Checked, chkV6.Checked ? int.Parse(txtV6Port.Text) : -1); } f.LoadLogConfigs(string.Format(Resources.LogConfig, Path.Combine(Core.LogDirectory, VPath.RemoveInvalidPathChars(txtName.Text)) + ".log", Path.Combine(Core.LogDirectory, VPath.RemoveInvalidPathChars(txtName.Text)) + ".error.log")); if (!string.IsNullOrWhiteSpace(txtCer.Text)) //BUG: logic error { if (!f.ImportCertificate(txtCer.Text, txtCerPwd.Text)) { var result = MessageBox.Show("未能加载TLS证书,可能是您输入的密码有误。\n点击“确定”不加载证书(不启用TLS),或点击“取消”重新输入密码", "TLS证书未导入", MessageBoxButtons.OKCancel); if (result != DialogResult.OK) { return; } } } Core.AddServerTab(f); this.Close(); } catch (Exception ex) { MessageBox.Show("创建服务器时发生错误。\n" + ex.ToString(), "ERROR"); //throw; } }
private bool DownloadFile(IChannelHandlerContext context, UpdateData data) { var ftpHelper = new FtpHelper(FtpConfig.FromConfiguration()); foreach (var file in data.Files) { var localPath = Path.Combine(data.Config.ServerRootPath, file.RelativePath); try { ftpHelper.Client.DownloadFile(localPath, file.FtpPath, FluentFTP.FtpLocalExists.Overwrite); WriteMessage(context, $" 文件{file.RelativePath}已下载.."); } catch (Exception ex) { WriteMessage(context, $" 文件{file.RelativePath}下载失败:{ex.Message}"); return(false); } } return(true); }
public async Task <FtpClientResponse> FtpWriteAsync(FtpConfig config, string data, string fileName, CancellationToken cancellationToken) { Func <string, Task <string> > myFunc = ConfigKeyVault.GetSecureSecret; FtpClientResponse response = new FtpClientResponse { ErrorMessage = "", Status = "", FileData = new List <FtpClientResponseFile>() }; try { response = await ActorFtpClient.WriteAsync(config, myFunc, Encoding.UTF8.GetBytes(data), fileName); } catch (Exception e) { await ActorFtpClient.Stop(); Logger.LogError(e, $"[FtpWriteAsync] Failed to write file: " + e.Message); } return(response); }