public FtpStatusCode UploadFile (string destination_path_name, Stream source, FtpTransferProgress callback, object state, int buffer_size) { FtpWebRequest req = null; FtpWebResponse resp = null; try { req = create_request(destination_path_name); req.Method = WebRequestMethods.Ftp.UploadFile; Stream req_stream = req.GetRequestStream(); //allocate buffer if (buffer_size == 0) { buffer_size = BUFFER_SIZE; } byte[] buffer = new byte[buffer_size]; int bytes_readed = 0; //callback variables long bytes_transferred = 0L; bool abort = false; do { //call callback bytes_transferred += bytes_readed; if (callback != null) { callback(bytes_transferred, ref abort, state); } if (abort) { break; } bytes_readed = source.Read(buffer, 0, buffer_size); req_stream.Write(buffer, 0, bytes_readed); } while (bytes_readed != 0); req_stream.Close(); resp = (FtpWebResponse)req.GetResponse(); //cache_remove(FtpPath.GetDirectory(destination_path_name)); return(resp.StatusCode); } finally { if (resp != null) { resp.Close(); } } }
public long DownloadFile(string path_name, Stream destination, FtpTransferProgress callback, object state, int buffer_size) { FtpWebRequest req = null; FtpWebResponse resp = null; long bytes_transferred = 0L; try { req = create_request(path_name); req.Method = WebRequestMethods.Ftp.DownloadFile; resp = (FtpWebResponse)req.GetResponse(); Stream resp_stream = resp.GetResponseStream(); //allocate buffer if (buffer_size == 0) { buffer_size = BUFFER_SIZE; } byte[] buffer = new byte[buffer_size]; int bytes_readed = 0; //callback variables bool abort = false; do { //call callback bytes_transferred += bytes_readed; if (callback != null) { callback(bytes_transferred, ref abort, state); } if (abort) { break; } bytes_readed = resp_stream.Read(buffer, 0, buffer_size); destination.Write(buffer, 0, bytes_readed); } while (bytes_readed != 0); resp_stream.Close(); } finally { if (resp != null) { resp.Close(); } } return(bytes_transferred); }
public FtpStatusCode AppendFile(string path_name, Stream data_to_append, FtpTransferProgress callback, object state) { FtpWebRequest req = null; FtpWebResponse resp = null; try { req = create_request(path_name); req.Method = WebRequestMethods.Ftp.AppendFile; Stream req_stream = req.GetRequestStream(); //allocate buffer byte[] buffer = new byte[BUFFER_SIZE]; int bytes_readed = 0; //callback variables long bytes_transferred = 0L; bool abort = false; do { //call callback bytes_transferred += bytes_readed; if (callback != null) { callback(bytes_transferred, ref abort, state); } if (abort) { break; } bytes_readed = data_to_append.Read(buffer, 0, BUFFER_SIZE); req_stream.Write(buffer, 0, bytes_readed); } while (bytes_readed != 0); //get response req_stream.Close(); resp = (FtpWebResponse)req.GetResponse(); cache_remove(FtpPath.GetDirectory(path_name)); return(resp.StatusCode); } finally { if (resp != null) { resp.Close(); } } }
public FtpDownloadEngine (FtpEntryInfo[] source, string destination, FtpConnection connection, FtpTransferOptions opts, CopyFileProgressDialog progress_window) { initial_source = source; initial_destination = destination; this.connection = connection; this.opts = opts; progress = progress_window; thread_background = new Thread(new ThreadStart(internal_do)); update_progress_delegate_holder = new MethodInvokerUpdateProgress(update_progress); if (progress_window != null) { progress_window.FormClosing += new FormClosingEventHandler(progress_dialog_FormClosing); } transfer_progress_delegate_holder = new FtpTransferProgress(ftp_transfer_proc); }