public Stream OpenRead(string path) { SetWorkingDirectory(path.Remove(path.LastIndexOf('/'))); FtpReply reply1 = Execute("TYPE I"); FtpDataStream socketData = OpenDataStream(); FtpReply reply2 = Execute("RETR {0}", path.Substring(path.LastIndexOf('/') + 1)); return(socketData); }
private FtpDataStream OpenDataStream() { FtpReply reply1 = Execute("PASV"); Match match = Regex.Match(reply1.Message, "(?<quad1>\\d+),(?<quad2>\\d+),(?<quad3>\\d+),(?<quad4>\\d+),(?<port1>\\d+),(?<port2>\\d+)"); IPAddress ipAddress = IPAddress.Parse(match.Groups["quad1"].Value + "." + match.Groups["quad2"].Value + "." + match.Groups["quad3"].Value + "." + match.Groups["quad4"].Value); int port = (int.Parse(match.Groups["port1"].Value) << 8) + int.Parse(match.Groups["port2"].Value); FtpDataStream dataStream = new FtpDataStream(); dataStream.Connect(ipAddress, port); dataStream.Closed += delegate { FtpReply reply2 = ReadReply(); }; return(dataStream); }
public List <string> ListDirectory(string path) { SetWorkingDirectory(path); List <string> lstDirectory = new List <string>(); FtpDataStream socketData = OpenDataStream(); FtpReply reply = Execute("LIST"); string str; while (!string.IsNullOrEmpty(str = socketData.ReadLine(_encoding))) { lstDirectory.Add(str); } socketData.Close(); return(lstDirectory); }