private bool SFTPDownload_DownloadRecursively(string remoteFilePath, string localDirectoryPath, ref bool overwite) { SFTPFileAttributes fileAttr; try { fileAttr = _sftp.GetFileInformations(remoteFilePath, false); } catch (SFTPClientException e) { if (!IsSFTPError(e, SFTPStatusCode.SSH_FX_NO_SUCH_FILE)) { throw; } // file missing or dead symbolic link ? Log(" | File: " + remoteFilePath); Log("*** Warning: " + e.Message); return(true); // skip } string fileName = GetUnixPathFileName(remoteFilePath); _sftp.ValidateLocalFileName(fileName, UnixPermissions.IsDirectory(fileAttr.Permissions)); // SFTPClientException may be thrown string localPath = Path.Combine(localDirectoryPath, fileName); // local path to save if (UnixPermissions.IsDirectory(fileAttr.Permissions)) { if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } SFTPFileInfo[] remoteFiles = _sftp.GetDirectoryEntries(remoteFilePath); foreach (SFTPFileInfo fileInfo in remoteFiles) { if (IsDots(fileInfo.FileName)) { continue; } string newRemoteFilePath = CombineUnixPath(remoteFilePath, fileInfo.FileName); bool cont = SFTPDownload_DownloadRecursively(newRemoteFilePath, localPath, ref overwite); if (!cont) { return(false); // cancel } } return(true); } else { if (!Directory.Exists(localDirectoryPath)) { Directory.CreateDirectory(localDirectoryPath); } bool cont = SFTPDownload_DownloadFile(remoteFilePath, fileName, localPath, fileAttr, ref overwite); return(cont); } }
private string GetTooltipText(SFTPFileInfo fileInfo) { return(new StringBuilder() .Append(UnixPermissions.Format(fileInfo.Permissions)) .Append(' ') .Append(fileInfo.FileSize) .Append(' ') .Append(fileInfo.FileName) .ToString()); }
private void SFTPOpenDirectory_Core(string fullPath, bool expand) { Log("Retrieving directory entries...: " + fullPath); SFTPFileInfo[] entries = _sftp.GetDirectoryEntries(fullPath); for (int i = 0; i < entries.Length; i++) { SFTPFileInfo ent = entries[i]; if (UnixPermissions.IsSymbolicLink(ent.Permissions)) { // If the symbolic link points a directory, // replace the file information so as to open the node. string path = CombineUnixPath(fullPath, ent.FileName); SFTPFileAttributes attr; try { attr = _sftp.GetFileInformations(path, false); } catch (SFTPClientException e) { if (!IsSFTPError(e, SFTPStatusCode.SSH_FX_NO_SUCH_FILE)) { throw; } // file missing or dead symbolic link ? attr = null; } if (attr != null) { if (UnixPermissions.IsDirectory(attr.Permissions)) { entries[i] = new SFTPFileInfo(ent.FileName, ent.LongName, attr); } } } } this.Invoke((MethodInvoker) delegate() { treeViewRemote.BeginUpdate(); TreeNode dirNode = MakeDirectoryTree(fullPath, expand); UpdateTreeDirectoryEntries(dirNode, entries); dirNode.EnsureVisible(); treeViewRemote.EndUpdate(); }); Log("...Done"); }
public static NodeTag CreateForFileOrDirectory(SFTPFileInfo fileInfo) { NodeType nodeType; string prefix; if (UnixPermissions.IsDirectory(fileInfo.Permissions)) { nodeType = NodeType.Directory; prefix = "D:"; } else if (UnixPermissions.IsSymbolicLink(fileInfo.Permissions)) { nodeType = NodeType.SymbolicLink; prefix = "F:"; } else { nodeType = NodeType.File; prefix = "F:"; } return(new NodeTag(nodeType, prefix + fileInfo.FileName, fileInfo)); }