private async Task ResolveLink(Link link) { try { //var relahref = link.Href.IsAbsoluteUri // ? link.Href.OriginalString.Remove(0, _cloud.Repo.PublicBaseUrlDefault.Length + 1) // : link.Href.OriginalString; //var infores = await new ItemInfoRequest(_cloud.CloudApi, link.Href, true).MakeRequestAsync(); var infores = await _cloud.Account.RequestRepo.ItemInfo(RemotePath.Get(link)); link.ItemType = infores.Body.Kind == "file" ? Cloud.ItemType.File : Cloud.ItemType.Folder; link.OriginalName = infores.Body.Name; link.Size = infores.Body.Size; link.IsResolved = true; } catch (Exception) //TODO check 404 etc. { //this means a bad link // don't know what to do link.IsBad = true; } }
protected override void ProcessRecord() { this.Session ??= new SshSession() { Server = this.Server, Port = this.Port, User = this.User, Password = this.Password, KeyboardInteractive = this.KeyboardInteractive, Effemeral = true, }; // 宛先に変数が含まれている場合、事前にSSHでコマンドを実行してパスを取得 if (candidate_envChar.Any(x => RemotePath.Contains(x))) { this.RemotePath = Session.ExecCommandOneLine($"echo {RemotePath}"); } // ダウンロード先パスの末尾に「\\」「/」が含まれている場合、対象ディレクトリ配下パスに変更 if (candidate_dirSeparator.Any(x => LocalPath.EndsWith(x))) { this.LocalPath = GetPathFromDirectory(RemotePath, LocalPath); } var client = Session.CreateAndConnectSftpClient(); if (client.IsConnected) { using (var fs = File.OpenWrite(LocalPath)) { client.DownloadFile(RemotePath, fs); } } Session.CloseIfEffemeral(); }
private string GetFullPath(string fileName) { Contract.Requires(!string.IsNullOrEmpty(Host)); string fullPath = string.Format("ftp://{0}/%2F", Host); if (RemotePath != null) { if (RemotePath.StartsWith("/")) { fullPath = string.Format("{0}/{1}", fullPath, RemotePath.Substring(1)); } else { fullPath = string.Format("{0}/{1}", fullPath, RemotePath); } } if (fileName == null) { return(fullPath); } else { return(string.Format("{0}/{1}", fullPath, fileName)); } }
private void DownloadEpgPackage(string archiveDirectory, string localDownloadDirectory) { SftpTransferOperationResult = false; var localfile = Path.Combine(localDownloadDirectory, LatestEpgPackage.Name); var archivedFile = Path.Combine(archiveDirectory, LatestEpgPackage.Name); if (System.IO.File.Exists(localfile) || System.IO.File.Exists(archivedFile)) { Console.WriteLine($"Epg file: {LatestEpgPackage.Name} has previously been downloaded."); } else { Console.WriteLine($"Downloading Latest EPG File: {LatestEpgPackage.Name} to {localDownloadDirectory}"); var operationResult = SftpSession.GetFiles(RemotePath.EscapeFileMask(LatestEpgPackage.FullName), localDownloadDirectory); if (operationResult.IsSuccess) { Console.WriteLine($"Remote File: {LatestEpgPackage.FullName} Downloaded successfully"); EpgTarBall = new FileInfo(localfile); SftpTransferOperationResult = true; } else { throw new Exception($"Failed to download file: {operationResult.Failures[0]}"); } } }
public override async Task <FileSystemExitCode> GetFileAsync(RemotePath remoteName, string localName, CopyFlags copyFlags, RemoteInfo remoteInfo, Action <int> setProgress, CancellationToken cancellationToken) { WsPath wsPath = remoteName; if (wsPath.Level == WsPathLevel.Account && wsPath.AccountName == ADD_NEW_ACCOUNT_TITLE) { return(FileSystemExitCode.NotSupported); } FileInfo localFileName = new FileInfo(localName); bool overWrite = (CopyFlags.Overwrite & copyFlags) != 0; bool performMove = (CopyFlags.Move & copyFlags) != 0; bool resume = (CopyFlags.Resume & copyFlags) != 0; if (resume) { return(FileSystemExitCode.NotSupported); } if (localFileName.Exists && !overWrite) { return(FileSystemExitCode.FileExists); } return(await _accountRepository[wsPath.AccountName].DownloadFile( wsPath, localFileName, overWrite, new Progress <int>(setProgress), performMove, cancellationToken )); }
static void DownloadFiles() { SessionOptions sessionOptions = new SessionOptions { Protocol = Protocol.Ftp, HostName = ApplicationSetting.FtpHost, UserName = ApplicationSetting.FtpUserName, Password = ApplicationSetting.FtpPassword //, //SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx..." }; string remotePath = ApplicationSetting.FtpRemoteFolder; string localPath = ApplicationSetting.LatestFilesPath; using (Session session = new Session()) { // Connect session.Open(sessionOptions); // Enumerate files and directories to download IEnumerable <RemoteFileInfo> fileInfos = session.EnumerateRemoteFiles( remotePath, null, EnumerationOptions.EnumerateDirectories | EnumerationOptions.AllDirectories); foreach (RemoteFileInfo fileInfo in fileInfos) { string localFilePath = RemotePath.TranslateRemotePathToLocal( fileInfo.FullName, remotePath, localPath); if (fileInfo.IsDirectory) { // Create local subdirectory, if it does not exist yet if (!Directory.Exists(localFilePath)) { Directory.CreateDirectory(localFilePath); } } else { Console.WriteLine("Downloading file {0}...", fileInfo.FullName); // Download file string remoteFilePath = RemotePath.EscapeFileMask(fileInfo.FullName); TransferOperationResult transferResult = session.GetFiles(remoteFilePath, localFilePath); // Did the download succeeded? if (!transferResult.IsSuccess) { // Print error (but continue with other files) Console.WriteLine( "Error downloading file {0}: {1}", fileInfo.FullName, transferResult.Failures[0].Message); } } } } }
public override async Task <SpecialCommandResult> Execute() { //var m = Regex.Match(Parames[0], @"(?snx-)\s* (https://?cloud.mail.ru/public)?(?<url>.*)/? \s*"); var m = Regex.Match(Parames[0], @"(?snx-)\s* (?<url>(https://?cloud.mail.ru/public)?.*)/? \s*"); if (!m.Success) { return(SpecialCommandResult.Fail); } var url = new Uri(m.Groups["url"].Value); //TODO: make method in MailRuCloud to get entry by url //var item = await new ItemInfoRequest(Cloud.CloudApi, m.Groups["url"].Value, true).MakeRequestAsync(); var item = await Cloud.Account.RequestRepo.ItemInfo(RemotePath.Get(new Link(url))); var entry = item.ToEntry(Cloud.Repo.PublicBaseUrlDefault); if (null == entry) { return(SpecialCommandResult.Fail); } string name = Parames.Count > 1 && !string.IsNullOrWhiteSpace(Parames[1]) ? Parames[1] : entry.Name; var res = await Cloud.LinkItem(new Uri(Cloud.Repo.PublicBaseUrlDefault + m.Groups["url"].Value, UriKind.Absolute), //m.Groups["url"].Value, Path, name, entry.IsFile, entry.Size, entry.CreationTimeUtc); return(new SpecialCommandResult(res)); }
public override async Task <SpecialCommandResult> Execute() { string target = Parames.Count > 0 && !string.IsNullOrWhiteSpace(Parames[0]) ? (Parames[0].StartsWith(WebDavPath.Separator) ? Parames[0] : WebDavPath.Combine(Path, Parames[0])) : Path; var resolvedTarget = await RemotePath.Get(target, Cloud.LinkManager); var data = await Cloud.Account.RequestRepo.FolderInfo(resolvedTarget); string resFilepath = WebDavPath.Combine(Path, data.Name + ".wdmrc.list.lst"); var sb = new StringBuilder(); foreach (var e in Flat(data, Cloud.LinkManager)) { string hash = (e as File)?.Hash.ToString() ?? "-"; string link = e.PublicLinks.Any() ? e.PublicLinks.First().Uri.OriginalString : "-"; sb.AppendLine( $"{e.FullPath}\t{e.Size.DefaultValue}\t{e.CreationTimeUtc:yyyy.MM.dd HH:mm:ss}\t{hash}\t{link}"); } Cloud.UploadFile(resFilepath, sb.ToString()); return(SpecialCommandResult.Success); }
protected override void Execute(CodeActivityContext context) { PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName]; IFtpSession ftpSession = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession; try { if (ftpSession == null) { throw new InvalidOperationException(Resources.FTPSessionNotFoundException); } ftpSession.Move(RemotePath.Get(context), NewPath.Get(context), Overwrite); } catch (Exception e) { if (ContinueOnError.Get(context)) { Trace.TraceError(e.ToString()); } else { throw; } } }
public async Task <FolderInfoResult> ItemInfo(RemotePath path, int offset = 0, int limit = Int32.MaxValue) { var req = await new ItemInfoRequest(HttpSettings, Authent, path, offset, limit).MakeRequestAsync(); var res = req; return(res); }
private async Task <IEnumerable <S3Object> > GetS3ObjectsList(RemotePath prefix) { if (prefix is null) { throw new ArgumentNullException(nameof(prefix)); } await Initialize().ConfigureAwait(false); var listRequest = new ListObjectsRequest { BucketName = _bucketName, Prefix = prefix, }; ListObjectsResponse listResponse; var list = new List <S3Object>(); do { listResponse = await Client.ListObjectsAsync(listRequest).ConfigureAwait(false); list.AddRange(listResponse.S3Objects); listRequest.Marker = listResponse.NextMarker; }while (!listResponse.IsTruncated); return(list.AsReadOnly()); }
public override bool RemoveDir(RemotePath remoteName) { if (_moveInProgress) { return(true); } WsPath wsPath = remoteName; switch (wsPath.Level) { case WsPathLevel.Root: return(false); case WsPathLevel.Account: if (_uiProvider.ShowMessage(string.Format(Resources.TextResource.UnregisterAccount, wsPath.AccountName), true)) { return(_accountRepository.UnRegisterAccount(_accountRepository[wsPath.AccountName])); } return(true); case WsPathLevel.AccessLevel: return(false); default: return(_accountRepository[wsPath.AccountName].DeleteFolder(wsPath)); } }
/// <summary> /// Download from ESP /// </summary> /// <param name="localName"></param> /// <param name="remoteName"></param> /// <param name="copyFlags"></param> /// <returns></returns> public override FileSystemExitCode PutFile(string localName, RemotePath remoteName, CopyFlags copyFlags) { MyLog($"PutFile ('{localName}')", remoteName); WccCall($"-p {remoteName.GetPort()} -up {localName} {remoteName.GetPathWithoutPort()}"); return(FileSystemExitCode.OK); //return base.PutFile(localName, remoteName, copyFlags); }
public override bool RemoveDir(RemotePath dirName) { MyLog("RemoveDir()", dirName); var result = ComCall(dirName.GetPort(), $"os.remove('{dirName.GetPathWithoutPort()}')\r\r"); return(result.StartsWith("true", StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// Copy to ESP /// </summary> /// <param name="remoteName"></param> /// <param name="localName"></param> /// <param name="copyFlags"></param> /// <param name="remoteInfo"></param> /// <returns></returns> public override FileSystemExitCode GetFile(RemotePath remoteName, string localName, CopyFlags copyFlags, RemoteInfo remoteInfo) { MyLog($"GetFile ('{localName}')", remoteName); WccCall($"-p {remoteName.GetPort()} -down {remoteName.GetPathWithoutPort()} {localName}"); return(FileSystemExitCode.OK); //return base.GetFile(remoteName, localName, copyFlags, remoteInfo); }
public void Extension() { RemotePath path = "/MyAccount/MyContainer/Folder1/Folder2/File.txt"; var actual = path.Extension; var expected = ".txt"; Assert.Equal(expected, actual); }
public void FileName() { RemotePath path = "/MyAccount/MyContainer/Folder1/Folder2/File.txt"; var actual = path.FileName; var expected = "File.txt"; Assert.Equal(expected, actual); }
public void Implicit_Postfix_String() { RemotePath path = @"\MyAccount\MyContainer\Folder1"; var actual = path + @"-file.exe"; var expected = @"\MyAccount\MyContainer\Folder1-file.exe"; Assert.Equal(expected, actual); }
public void Implicit_Prefix_String() { RemotePath path = @"\MyAccount\MyContainer\Folder1"; var actual = "/hoi" + path; var expected = @"\hoi\MyAccount\MyContainer\Folder1"; Assert.Equal(expected, actual); }
public void Implicit_Add_SubPath() { RemotePath path = @"\MyAccount\MyContainer\Folder1\"; var actual = path + ((RemotePath)@"\subPath\file.exe"); var expected = @"\MyAccount\MyContainer\Folder1\subPath\file.exe"; Assert.Equal(expected, actual); }
public async Task <bool> TryPurge(RemotePath prefix) { if (!_dryRun) { await _amazonFunctions.Purge(prefix).ConfigureAwait(false); } return(!_dryRun); }
public static string GetPathWithoutPort(this RemotePath path) { if (path.Segments.Length > 1) { return("/" + string.Join("/", path.Segments, 1, path.Segments.Length - 1)); } return("/"); }
public void Keep_TrailingSlash() { RemotePath path = "/some/folder/"; Assert.Equal(@"\some\folder\", (string)path); RemotePath path2 = @"\some\folder\"; Assert.Equal(@"\some\folder\", (string)path2); }
public void GetSegment() { RemotePath path = "/segment1/segment2/segment3/segment4"; Assert.Null(path.GetSegment(0)); Assert.Equal("segment1", path.GetSegment(1)); Assert.Equal("segment2", path.GetSegment(2)); Assert.Equal("segment3", path.GetSegment(3)); Assert.Equal("segment4", path.GetSegment(4)); }
/// <summary> /// </summary> /// <param name="session"></param> /// <param name="fileName">"/home/user/file.name.txt"</param> /// <param name="localPath"></param> public void DownloadFileRemoteDir(SessionOptions options, string fileName, string localPath) { using var session = new Session(); // Connect session.Open(options); // Download the selected file //check // Throw on any error session.GetFiles(RemotePath.EscapeFileMask(fileName), localPath).Check(); }
public async Task <bool> TryPurge(RemotePath prefix) { if (!await _inner.TryPurge(prefix).ConfigureAwait(false)) { _log.PutOut($"Purge skipped."); return(false); } return(true); }
public override PreviewBitmapResult GetPreviewBitmap(RemotePath remoteName, int width, int height) { WsPath sourcePath = remoteName; if (sourcePath.Level == WsPathLevel.Folder && sourcePath.Parent != "/") // Preview for root folder not supported { return(_accountRepository[sourcePath.AccountName].GetPreviewBitmap(sourcePath, width, height)); } return(base.GetPreviewBitmap(remoteName, width, height)); }
public async Task <IEntry> FolderInfo(RemotePath path, int offset = 0, int limit = int.MaxValue, int depth = 1) { if (path.IsLink) { throw new NotImplementedException(nameof(FolderInfo)); } var req = new ListRequest(HttpSettings, Authent, _metaServer.Value.Url, path.Path, _listDepth); var res = await req.MakeRequestAsync(); switch (res.Item) { case FsFolder fsFolder: { var f = new Folder(fsFolder.Size == null ? 0 : (long)fsFolder.Size.Value, fsFolder.FullPath); foreach (var fsi in fsFolder.Items) { if (fsi is FsFile fsfi) { var fi = new File(fsfi.FullPath, (long)fsfi.Size, new FileHashMrc(fsfi.Sha1)) { CreationTimeUtc = fsfi.ModifDate, LastWriteTimeUtc = fsfi.ModifDate }; f.Files.Add(fi); } else if (fsi is FsFolder fsfo) { var fo = new Folder(fsfo.Size == null ? 0 : (long)fsfo.Size.Value, fsfo.FullPath); f.Folders.Add(fo); } else { throw new Exception($"Unknown item type {fsi.GetType()}"); } } return(f); } case FsFile fsFile: { var fi = new File(fsFile.FullPath, (long)fsFile.Size, new FileHashMrc(fsFile.Sha1)) { CreationTimeUtc = fsFile.ModifDate, LastWriteTimeUtc = fsFile.ModifDate }; return(fi); } default: return(null); } }
//************************************************************************************************************* private void RemotePin_Click(object sender, EventArgs e) { if (RemotePath.FindStringExact(RemoteList.CurrentDirectory) == -1) { RemoteList.PinFolder(); } else { RemoteList.UnpinFolder(); } }
public async Task Purge(RemotePath prefix) { if (prefix is null) { throw new ArgumentNullException(nameof(prefix)); } _log.PutOut($"Purge bucket with remote path {prefix}"); await _inner.Purge(prefix).ConfigureAwait(false); _log.PutOut($"Purge completed."); }