Exemplo n.º 1
0
        /// <summary>
        /// Deletes the specified file and removes it from the list of files in this
        /// directory if it's there
        /// </summary>
        /// <param name="file"></param>
        public void Delete(FtpFile file)
        {
            this.Client.RemoveFile(file.FullName);

            if (this._files.Contains(file))
            {
                this._files.Remove(file);
#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format("Removed {0} from my file list!", file.FullName));
#endif
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Downloads a file from the server
 /// </summary>
 /// <param name="remote"></param>
 /// <param name="local"></param>
 /// <example>
 ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
 /// </example>
 public void Download(FtpFile remote, string local) {
     this.Download(remote, local, FtpDataType.Binary, 0);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Uploads a stream to the specified remote file
        /// </summary>
        /// <param name="istream"></param>
        /// <param name="remote"></param>
        /// <param name="datatype"></param>
        /// <param name="rest"></param>
        /// <example>
        ///     <code source="..\Examples\Upload\Program.cs" lang="cs"></code>
        /// </example>
        public void Upload(Stream istream, FtpFile remote, FtpDataType datatype, long rest) {
            long size = 0;
            long total = 0;
            int read = 0;

            if (istream == null) {
                throw new ArgumentException("istream is null");
            }

            if (remote == null) {
                throw new ArgumentException("remote is null");
            }

            if (!istream.CanRead) {
                throw new ArgumentException("istream is not readable");
            }

            if (istream.CanSeek) {
                size = istream.Length;

                if (rest > 0) { // set resume position
                    istream.Seek(rest, SeekOrigin.Begin);
                    total = rest;
                }
            }
            else {
                rest = 0;
            }

            using (FtpDataStream ch = this.OpenWrite(remote.FullName, datatype, rest)) {
                byte[] buf = new byte[ch.SendBufferSize];
                DateTime start = DateTime.Now;
                FtpTransferInfo e;

                while ((read = istream.Read(buf, 0, buf.Length)) > 0) {
                    ch.Write(buf, 0, read);
                    total += read;
                    e = new FtpTransferInfo(FtpTransferType.Upload, remote.FullName, size, rest, total, start, false);

                    this.OnTransferProgress(e);
                    if (e.Cancel) {
                        break;
                    }
                }

                // fire one more time to let event handler know the transfer is complete
                this.OnTransferProgress(new FtpTransferInfo(FtpTransferType.Upload, remote.FullName,
                    size, rest, total, start, true));
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Downloads a file from the server to the current working directory
 /// </summary>
 /// <param name="remote"></param>
 /// <example>
 ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
 /// </example>
 public void Download(FtpFile remote) {
     this.Download(remote, string.Format(@"{0}\{1}",
         Environment.CurrentDirectory, remote.Name));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Uploads a file to the server
 /// </summary>
 /// <param name="istream">The stream to upload</param>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="datatype">ASCII/Binary</param>
 /// <example>
 ///     <code source="..\Examples\Upload\Program.cs" lang="cs"></code>
 /// </example>
 public void Upload(Stream istream, FtpFile remote, FtpDataType datatype) {
     this.Upload(istream, remote, datatype, 0);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Uploads a file to the server
 /// </summary>
 /// <param name="remote">Local path of the file</param>
 /// <param name="local">Remote path of the file</param>
 /// <param name="datatype">ASCII/Binary</param>
 /// <param name="rest">Resume location</param>
 /// <example>
 ///     <code source="..\Examples\Upload\Program.cs" lang="cs"></code>
 /// </example>
 public void Upload(string local, FtpFile remote, FtpDataType datatype, long rest) {
     using (FileStream istream = new FileStream(local, FileMode.Open, FileAccess.Read)) {
         try {
             this.Upload(istream, remote, datatype, rest);
         }
         finally {
             istream.Close();
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Uploads a file to the server
 /// </summary>
 /// <param name="istream">The file to upload</param>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="rest">Resume location</param>
 /// <example>
 ///     <code source="..\Examples\Upload\Program.cs" lang="cs"></code>
 /// </example>
 public void Upload(Stream istream, FtpFile remote, long rest) {
     this.Upload(istream, remote, FtpDataType.Binary, rest);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Uploads a file to the server
 /// </summary>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="local">Local path of the file</param>
 /// <param name="datatype">ASCII/Binary</param>
 /// <example>
 ///     <code source="..\Examples\Upload\Program.cs" lang="cs"></code>
 /// </example>
 public void Upload(string local, FtpFile remote, FtpDataType datatype) {
     this.Upload(local, remote, datatype, 0);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Downloads the remote file to the specified stream
        /// </summary>
        /// <param name="remote"></param>
        /// <param name="ostream"></param>
        /// <param name="datatype"></param>
        /// <param name="rest"></param>
        /// <example>
        ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
        /// </example>
        public void Download(FtpFile remote, Stream ostream, FtpDataType datatype, long rest) {
            long size = remote.Length;
            long total = 0;
            int read = 0;

            if (remote == null) {
                throw new ArgumentException("remote is null");
            }

            if (ostream == null) {
                throw new ArgumentException("ostream is null");
            }

            if (!ostream.CanWrite) {
                throw new ArgumentException("ostream is not writable");
            }

            if (rest > 0 && ostream.CanSeek) { // set reset position
                ostream.Seek(rest, SeekOrigin.Begin);
                total = rest;
            }
            else if (!ostream.CanSeek) {
                rest = 0;
            }

            try {
                using (FtpDataStream ch = this.OpenRead(remote.FullName, datatype, rest)) {
                    byte[] buf = new byte[ch.ReceiveBufferSize];
                    DateTime start = DateTime.Now;
                    FtpTransferInfo e = null;

                    while ((read = ch.Read(buf, 0, buf.Length)) > 0) {
                        ostream.Write(buf, 0, read);
                        total += read;
                        e = new FtpTransferInfo(FtpTransferType.Download, remote.FullName, size, rest, total, start, false);

                        this.OnTransferProgress(e);
                        if (e.Cancel) {
                            break;
                        }
                    }

                    // fire one more time to let event handler know that the transfer is complete
                    this.OnTransferProgress(new FtpTransferInfo(FtpTransferType.Download, remote.FullName,
                        size, rest, total, start, true));
                }
            }
            finally {
                ostream.Flush();
            }
        }
Exemplo n.º 10
0
 /// <summary>
 /// Uploads a file to the server
 /// </summary>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="local">Local path of the file</param>
 /// <param name="rest">Resume location</param>
 /// <example>
 ///     <code source="..\Examples\Upload\Program.cs" lang="cs"></code>
 /// </example>
 public void Upload(string local, FtpFile remote, long rest) {
     this.Upload(local, remote, FtpDataType.Binary, rest);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Downloads the specified file from the server
 /// </summary>
 /// <param name="remote"></param>
 /// <param name="local"></param>
 /// <param name="datatype"></param>
 /// <param name="rest"></param>
 /// <example>
 ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
 /// </example>
 public void Download(FtpFile remote, string local, FtpDataType datatype, long rest) {
     using (FileStream ostream = new FileStream(local, FileMode.OpenOrCreate, FileAccess.Write)) {
         try {
             this.Download(remote, ostream, datatype, rest);
         }
         finally {
             ostream.Close();
         }
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Downloads a file from the server
 /// </summary>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="ostream">The stream to download the file to</param>
 /// <param name="datatype">ASCII/Binary</param>
 /// <example>
 ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
 /// </example>
 public void Download(FtpFile remote, Stream ostream, FtpDataType datatype) {
     this.Download(remote, ostream, datatype, 0);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Downloads a file from the server
 /// </summary>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="local">Local path of the file</param>
 /// <param name="datatype">ASCII/Binary</param>
 /// <example>
 ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
 /// </example>
 public void Download(FtpFile remote, string local, FtpDataType datatype) {
     this.Download(remote, local, datatype, 0);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Downloads a file from the server
 /// </summary>
 /// <param name="remote">Remote path of the file</param>
 /// <param name="ostream">Local path of the file</param>
 /// <param name="rest">Resume location</param>
 /// <example>
 ///     <code source="..\Examples\Download\Program.cs" lang="cs"></code>
 /// </example>
 public void Download(FtpFile remote, Stream ostream, long rest) {
     this.Download(remote, ostream, FtpDataType.Binary, rest);
 }
Exemplo n.º 15
0
		/// <summary>
		/// Deletes the specified file and removes it from the list of files in this
		/// directory if it's there
		/// </summary>
		/// <param name="file"></param>
		public void Delete(FtpFile file) {
			this.Client.RemoveFile(file.FullName);

			if(this._files.Contains(file)) {
				this._files.Remove(file);
#if DEBUG
				System.Diagnostics.Debug.WriteLine(string.Format("Removed {0} from my file list!", file.FullName));
#endif
			}
		}