// Convert a string instance of a URI to a relative FTP path // Return the file name or the folder name public static string ToFtpPath(string s) { bool isDir = s.EndsWith(@"/"); if (isDir) { // Note: append the directory end tag "/" return(FileNameHelpers.GetDirectoryName(s) + "/"); } // the path is a file else { return(FileNameHelpers.GetFileName(s)); } }
protected string GenerateEntry(IFileInfo info) { StringBuilder entry = new StringBuilder(); bool isDirectory = info.IsDirectory(); if (isDirectory) { entry.Append("Type=dir; "); string dirName = FileNameHelpers.GetDirectoryName(info.Path()); entry.Append(dirName); } else { entry.Append(string.Format("Type=file;Size={0};Modify={1}; ", info.GetSize(), info.GetModifiedTime().ToString("yyyyMMddHHmmss"))); entry.Append(FileNameHelpers.GetFileName(info.Path())); } return(entry.ToString()); }
// build short list reply, only list the file names protected string BuildShortReply(string[] asFiles, string[] asDirectories) { var stringBuilder = new StringBuilder(); if (asFiles != null) { foreach (string filePath in asFiles) { stringBuilder.Append(string.Format("{0}\r\n", FileNameHelpers.GetFileName(filePath))); } } if (asDirectories != null) { foreach (string dirPath in asDirectories) { stringBuilder.Append(string.Format("{0}\r\n", FileNameHelpers.GetDirectoryName(dirPath))); } } return(stringBuilder.ToString()); }
private string GetLongProperty(IFileInfo info) { if (info == null) { return(null); } var stringBuilder = new StringBuilder(); // permissions string sAttributes = info.GetAttributeString(); stringBuilder.Append(sAttributes); stringBuilder.Append(" 1 owner group"); // check whether info is directory bool isDirectory = info.IsDirectory(); // size string sFileSize = info.GetSize().ToString(); // if info is directory, the size will be 1 stringBuilder.Append(TextHelpers.RightAlignString(sFileSize, 13, ' ')); stringBuilder.Append(" "); // modify time DateTimeOffset fileDate = info.GetModifiedTime(); //if info is directory, the modify time will be the current time // month stringBuilder.Append(TextHelpers.Month(fileDate.Month)); stringBuilder.Append(" "); // day string sDay = fileDate.Day.ToString(); if (sDay.Length == 1) { stringBuilder.Append(" "); } stringBuilder.Append(sDay); stringBuilder.Append(" "); // year or hour:min if (fileDate.Year < DateTime.Now.Year) { stringBuilder.Append(" " + fileDate.Year); } else { stringBuilder.Append(string.Format("{0:hh}:{1:mm}", fileDate, fileDate)); } stringBuilder.Append(" "); // filename string path = info.Path(); if (isDirectory) { stringBuilder.Append(FileNameHelpers.GetDirectoryName(path)); } else { stringBuilder.Append(FileNameHelpers.GetFileName(path)); } // end stringBuilder.Append("\r\n"); return(stringBuilder.ToString()); }