public FtpMediaStream(IngestMedia media, bool forWrite) { if (media?.Directory == null) { throw new ApplicationException(); } var uri = new Uri(media.FullPath); _client = new System.Net.FtpClient.FtpClient { Credentials = ((IngestDirectory)media.Directory).GetNetworkCredential(), Host = uri.Host }; try { _client.Connect(); _ftpStream = forWrite ? _client.OpenWrite(uri.LocalPath) : _client.OpenRead(uri.LocalPath); } catch { _client.Dispose(); throw; } }
public FtpMediaStream(IngestMedia media, bool forWrite) { _media = media; if (media == null || media.Directory == null) { throw new ApplicationException(); } Uri uri = new Uri(media.FullPath); _client = new System.Net.FtpClient.FtpClient(); _client.Credentials = ((IngestDirectory)media.Directory)._getNetworkCredential(); _client.Host = uri.Host; try { _client.Connect(); if (forWrite) { _ftpStream = _client.OpenWrite(uri.LocalPath); } else { _ftpStream = _client.OpenRead(uri.LocalPath); } } catch { _client.Dispose(); throw; } }
private void DownloadBtn_Click(object sender, RoutedEventArgs e) { try { using (var ftpClient = new System.Net.FtpClient.FtpClient()) { var destPath = RemoteDirectoryTB.Text; var sourcePath = LocalFilenameTB.Text; ftpClient.Host = HostTB.Text; ftpClient.Credentials = new System.Net.NetworkCredential(UserTB.Text, PasswordTB.Password); ftpClient.EncryptionMode = System.Net.FtpClient.FtpEncryptionMode.None; ftpClient.Connect(); using (var fileStream = File.OpenRead(sourcePath)) using (var ftpStream = ftpClient.OpenWrite(string.Format("{0}/{1}", destPath, System.IO.Path.GetFileName(sourcePath)))) { var buffer = new byte[8 * 1024]; int count; while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0) { ftpStream.Write(buffer, 0, count); } } } } catch (Exception ex) { // Typical exceptions here are IOException, SocketException, or a FtpCommandException //TODO catch some exceptions here and report them } }
public FtpDataStream(System.Net.FtpClient.FtpClient conn) { if (conn == null) { throw new ArgumentException("The control connection cannot be null."); } this.ControlConnection = conn; base.ValidateCertificate += (obj, e) => e.Accept = true; this.m_position = 0L; }
protected override void Dispose(bool disposing) { if (disposing) { if (base.IsConnected) { this.Close(); } this.m_control = null; } base.Dispose(disposing); }
/// <summary> /// Invia un testo (con codifica Unicode) tramite FTP. /// </summary> /// <param name="contenuto">Il testo da inviare.</param> /// <param name="host"></param> /// <param name="usr"></param> /// <param name="pwd"></param> /// <param name="fileName">Path e nome del file di destinazione.</param> private void SendFtp(string contenuto, string host, string usr, string pwd, string fileName) { // upload di un file tramite ftp using (System.Net.FtpClient.FtpClient client = new System.Net.FtpClient.FtpClient()) { client.Host = host; client.Credentials = new System.Net.NetworkCredential(usr, pwd); client.Connect(); using (var ftpStream = client.OpenWrite(fileName)) { byte[] buffer = System.Text.ASCIIEncoding.Unicode.GetBytes(contenuto); ftpStream.Write(buffer, 0, buffer.Length); } } }
public FtpReply Close() { base.Close(); try { if (this.ControlConnection != null) { return(this.ControlConnection.CloseDataStream(this)); } } finally { this.m_commandStatus = new FtpReply(); this.m_control = null; } return(new FtpReply()); }
public FtpMediaStream(IngestMedia media) { _media = media; if (media == null || media.Directory == null) throw new ApplicationException(); Uri uri = new Uri(media.FullPath); _client = new System.Net.FtpClient.FtpClient(); _client.Credentials = media.Directory.NetworkCredential; _client.Host = uri.Host; try { _client.Connect(); _ftpStream = _client.OpenRead(uri.LocalPath); } catch { _client.Dispose(); } }
private void button1_Click(object sender, EventArgs e) { try { //client = new TcpClient(Dns.GetHostEntry(textBox1.Text.Trim()).HostName, 21); //ftp = new SharpFtpServer.ClientConnection(client); //ftp = new FtpConnection(textBox1.Text.Trim(), 21, "harve", "kell654321"); //ftp.LocalDirectory = localPath; ftp = new System.Net.FtpClient.FtpClient("kell", "123", textBox1.Text.Trim(), 21); ftp.SetWorkingDirectory(localPath); ftp.Connect(); RefreshRemoteList(); listBox1.Enabled = listBox2.Enabled = true; MessageBox.Show("连接成功!"); } catch (Exception ex) { MessageBox.Show("连接失败:" + ex.Message); } }
public override void Execute(Options options, System.Net.FtpClient.FtpClient client) { if (options == null) { throw new ArgumentNullException("options"); } if (client == null) { throw new ArgumentNullException("client"); } foreach (var f in options.File.Split(',')) { var fileName = Path.GetFileName(f); if (File.Exists(f)) { using (Stream ostream = client.OpenWrite(fileName)) { try { using (var source = File.OpenRead(f)) { source.CopyTo(ostream); } } finally { ostream.Close(); } } } else { Console.WriteLine("file [{0}] not exits.", fileName); } } }
public FtpClientSendingProvider(System.Net.FtpClient.FtpClient ftpClient) { this.ftpClient = ftpClient; }