Example #1
0
        public static void BeginOpenWrite() {
            // The using statement here is OK _only_ because m_reset.WaitOne()
            // causes the code to block until the async process finishes, otherwise
            // the connection object would be disposed early. In practice, you
            // typically would not wrap the following code with a using statement.
            using (FtpClient conn = new FtpClient()) {
                m_reset.Reset();

                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.BeginOpenWrite("/path/to/file",
                    new AsyncCallback(BeginOpenWriteCallback), conn);

                m_reset.WaitOne();
                conn.Disconnect();
            }
        }
Example #2
0
        public static void BeginOpenWrite()
        {
            // The using statement here is OK _only_ because m_reset.WaitOne()
            // causes the code to block until the async process finishes, otherwise
            // the connection object would be disposed early. In practice, you
            // typically would not wrap the following code with a using statement.
            using (var conn = new FtpClient()) {
                m_reset.Reset();

                conn.Host        = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");
                conn.BeginOpenWrite("/path/to/file", BeginOpenWriteCallback, conn);

                m_reset.WaitOne();
                conn.Disconnect();
            }
        }
Example #3
0
        public override void send(FileInf[] files)
        {
            try
            {
                FtpClient client = new FtpClient();
                client.Host           = this.Server;
                client.Port           = this.Port;
                client.Credentials    = new NetworkCredential(this.User, this.Password);
                client.EncryptionMode = FtpEncryptionMode.Explicit; // FTPS

                client.Connect();
                client.SetWorkingDirectory(this.Path);

                foreach (FileInf file in files)
                {
                    try
                    {
                        client.BeginOpenWrite(file.FileName, FtpDataType.Binary,
                                              new AsyncCallback(PluginFTP.BeginOpenWriteCallback), new AsyncCallbackState(client, file));

                        m_reset.WaitOne();
                        this.Task.InfoFormat("[PluginFTPS] file {0} sent to {1}.", file.Path, this.Server);
                    }
                    catch (ThreadAbortException)
                    {
                        throw;
                    }
                    catch (Exception e)
                    {
                        this.Task.ErrorFormat("[PluginFTPS] An error occured while sending the file {0} to {1}. Error message: {2}", file.Path, this.Server, e.Message);
                    }
                }

                client.Disconnect();
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception e)
            {
                this.Task.ErrorFormat("[PluginFTPS] An error occured while sending files.", e);
            }
        }