Ejemplo n.º 1
0
        public String Upload(UploadTask task)
        {
            FtpWebRequest ftpRequest = null;
            Stream ftpStream = null;
            int bufferSize = 8192;

            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(Host + "/" + task.Remote);
            ftpRequest.Credentials = new NetworkCredential(Login, Password);
            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;
            ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

            ftpStream = ftpRequest.GetRequestStream();
            var localFileStream = new FileStream(task.Local, FileMode.Open);
            var byteBuffer = new byte[bufferSize];
            int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
            while (bytesSent != 0)
            {
                ftpStream.Write(byteBuffer, 0, bytesSent);
                bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
            }
            localFileStream.Close();
            ftpStream.Close();
            ftpRequest = null;

            return String.Format("{0}", task.Name);
        }
Ejemplo n.º 2
0
 String UploadTask(UploadTask task)
 {
     return _ftpUploader.Upload(task);
 }
Ejemplo n.º 3
0
 public void AddRequest(UploadTask task)
 {
     _tasks.Add(task);
 }