public SocksProxy(string destinationHost, int destinationPort, FtpSocketStream socketStream) { _buffer = new byte[512]; _destinationHost = destinationHost; _destinationPort = destinationPort; _socketStream = socketStream; }
private FtpReply GetProxyReply(FtpSocketStream stream) { FtpReply reply = new FtpReply(); string buf; lock (Lock) { if (!IsConnected) { throw new InvalidOperationException("No connection to the server has been established."); } stream.ReadTimeout = ReadTimeout; while ((buf = stream.ReadLine(Encoding)) != null) { Match m; FtpTrace.WriteLine(buf); if ((m = Regex.Match(buf, @"^HTTP/.*\s(?<code>[0-9]{3}) (?<message>.*)$")).Success) { reply.Code = m.Groups["code"].Value; reply.Message = m.Groups["message"].Value; break; } reply.InfoMessages += string.Format("{0}\n", buf); } } return(reply); }
private async Task ProxyHandshakeAsync(FtpSocketStream stream, CancellationToken token = default(CancellationToken)) { var proxyConnectionReply = await GetProxyReplyAsync(stream, token); if (!proxyConnectionReply.Success) { throw new FtpException("Can't connect " + Host + " via proxy " + Proxy.Host + ".\nMessage : " + proxyConnectionReply.ErrorMessage); } }
private void ProxyHandshake(FtpSocketStream stream) { var proxyConnectionReply = GetProxyReply(stream); if (!proxyConnectionReply.Success) { throw new FtpException("Can't connect " + Host + " via proxy " + Proxy.Host + ".\nMessage : " + proxyConnectionReply.ErrorMessage); } }
protected override void Connect(FtpSocketStream stream) { base.Connect(stream); var proxy = new SocksProxy(Host, Port, stream); proxy.Negotiate(); proxy.Authenticate(); proxy.Connect(); }
protected override void Connect(FtpSocketStream stream, string host, int port, FtpIpVersion ipVersions) { base.Connect(stream); var proxy = new SocksProxy(Host, port, stream); proxy.Negotiate(); proxy.Authenticate(); proxy.Connect(); }
protected override async Task ConnectAsync(FtpSocketStream stream, CancellationToken cancellationToken) { await base.ConnectAsync(stream, cancellationToken); var proxy = new SocksProxy(Host, Port, stream); await proxy.NegotiateAsync(); await proxy.AuthenticateAsync(); await proxy.ConnectAsync(); }
private FtpReply GetProxyReply(FtpSocketStream stream) { var reply = new FtpReply(); string buf; #if !CORE14 lock (Lock) { #endif if (!IsConnected) { throw new InvalidOperationException("No connection to the server has been established."); } stream.ReadTimeout = ReadTimeout; while ((buf = stream.ReadLine(Encoding)) != null) { Match m; LogLine(FtpTraceLevel.Info, buf); if ((m = Regex.Match(buf, @"^HTTP/.*\s(?<code>[0-9]{3}) (?<message>.*)$")).Success) { reply.Code = m.Groups["code"].Value; reply.Message = m.Groups["message"].Value; break; } reply.InfoMessages += buf + "\n"; } // fixes #84 (missing bytes when downloading/uploading files through proxy) while ((buf = stream.ReadLine(Encoding)) != null) { LogLine(FtpTraceLevel.Info, buf); if (FtpExtensions.IsNullOrWhiteSpace(buf)) { break; } reply.InfoMessages += buf + "\n"; } #if !CORE14 } #endif return(reply); }
protected override void Connect(FtpSocketStream stream, string host, int port, FtpIpVersion ipVersions) { base.Connect(stream, host, port, ipVersions); var writer = new StreamWriter(BaseStream); writer.Write("CONNECT {0}:{1} HTTP/1.1", Host, Port); writer.Write("Host: {0}:{1}", Host, Port); if (Proxy.Credentials != null) { var credentialsHash = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(string.Format("{0}:{1}", Proxy.Credentials.UserName, Proxy.Credentials.Password))); writer.WriteLine("Proxy-Authorization: Basic {0}", credentialsHash); } writer.WriteLine("User-Agent: custom-ftp-client"); writer.WriteLine(); writer.Flush(); }
private async Task <FtpReply> GetProxyReplyAsync(FtpSocketStream stream, CancellationToken token = default(CancellationToken)) { FtpReply reply = new FtpReply(); string buf; if (!IsConnected) { throw new InvalidOperationException("No connection to the server has been established."); } stream.ReadTimeout = ReadTimeout; while ((buf = await stream.ReadLineAsync(Encoding, token)) != null) { Match m; this.LogLine(FtpTraceLevel.Info, buf); if ((m = Regex.Match(buf, @"^HTTP/.*\s(?<code>[0-9]{3}) (?<message>.*)$")).Success) { reply.Code = m.Groups["code"].Value; reply.Message = m.Groups["message"].Value; break; } reply.InfoMessages += (buf + "\n"); } // fixes #84 (missing bytes when downloading/uploading files through proxy) while ((buf = await stream.ReadLineAsync(Encoding, token)) != null) { this.LogLine(FtpTraceLevel.Info, buf); if (FtpExtensions.IsNullOrWhiteSpace(buf)) { break; } reply.InfoMessages += (buf + "\n"); } return(reply); }
/// <summary> /// Connects to the server using an existing <see cref="FtpSocketStream"/> /// </summary> /// <param name="stream">The existing socket stream</param> /// <param name="host">Host name</param> /// <param name="port">Port number</param> /// <param name="ipVersions">IP version to use</param> /// <param name="token">IP version to use</param> protected override async Task ConnectAsync(FtpSocketStream stream, string host, int port, FtpIpVersion ipVersions, CancellationToken token) { await base.ConnectAsync(stream, token); var writer = new StreamWriter(stream); await writer.WriteLineAsync(string.Format("CONNECT {0}:{1} HTTP/1.1", host, port)); await writer.WriteLineAsync(string.Format("Host: {0}:{1}", host, port)); if (Proxy.Credentials != null) { var credentialsHash = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Proxy.Credentials.UserName + ":" + Proxy.Credentials.Password)); await writer.WriteLineAsync("Proxy-Authorization: Basic " + credentialsHash); } await writer.WriteLineAsync("User-Agent: custom-ftp-client"); await writer.WriteLineAsync(); await writer.FlushAsync(); await ProxyHandshakeAsync(stream, token); }
/// <summary> Redefine connect for FtpClient : authentication on the Proxy </summary> /// <param name="stream">The socket stream.</param> protected override void Connect(FtpSocketStream stream, string host, int port, FtpIpVersion ipVersions) { stream.Connect(Proxy.Host, Proxy.Port, InternetProtocolVersions); }
/// <summary> Redefine connect for FtpClient : authentication on the Proxy </summary> /// <param name="stream">The socket stream.</param> /// <param name="token">Cancellation token.</param> protected override Task ConnectAsync(FtpSocketStream stream, CancellationToken token) { return(stream.ConnectAsync(Proxy.Host, Proxy.Port, InternetProtocolVersions, token)); }
/// <summary> Redefine connect for FtpClient : authentication on the Proxy </summary> /// <param name="stream">The socket stream.</param> protected override void Connect(FtpSocketStream stream) { stream.Connect(Proxy.Host, Proxy.Port, InternetProtocolVersions); }
/// <summary> /// Connects to the server using an existing <see cref="FtpSocketStream"/> /// </summary> /// <param name="stream">The existing socket stream</param> protected override void Connect(FtpSocketStream stream) { Connect(stream, Host, Port, FtpIpVersion.ANY); }
/// <summary> /// Connects to the server using an existing <see cref="FtpSocketStream"/> /// </summary> /// <param name="stream">The existing socket stream</param> protected override Task ConnectAsync(FtpSocketStream stream) { return(ConnectAsync(stream, Host, Port, FtpIpVersion.ANY)); }
/// <summary> /// Connects to the server using an existing <see cref="FtpSocketStream"/> /// </summary> /// <param name="stream">The existing socket stream</param> protected override Task ConnectAsync(FtpSocketStream stream, CancellationToken token) { return(ConnectAsync(stream, Host, Port, FtpIpVersion.ANY, token)); }
/// <summary> Redefine connect for FtpClient : authentication on the Proxy </summary> /// <param name="stream">The socket stream.</param> protected override Task ConnectAsync(FtpSocketStream stream) { return(stream.ConnectAsync(Proxy.Host, Proxy.Port, InternetProtocolVersions)); }