public virtual void ResumeGet() { log.Debug("ResumeGet()"); try { Connect(); Login(); // move to test directory ftp.ChDir(testdir); ftp.TransferType = FTPTransferType.BINARY; // put to a random filename string filename1 = GenerateRandomFilename(); // set up event handler to cancel the transfer cancelled = false; BytesTransferredHandler handler = new BytesTransferredHandler(BytesTransferred); ftp.BytesTransferred += handler; // initiate the get log.Debug("Getting '" + remoteBinaryFile + "' to '" + filename1 + "'"); ftp.Get(localDataDir + filename1, remoteBinaryFile); // remove handler for next transfer ftp.BytesTransferred -= handler; // should be cancelled - now resume ftp.Resume(); // get again - should append log.Debug("Resuming '" + remoteBinaryFile + "' to '" + filename1 + "'"); ftp.Get(localDataDir + filename1, remoteBinaryFile); string filename2 = GenerateRandomFilename();; // do another get - complete this time ftp.Get(localDataDir + filename2, remoteBinaryFile); // check equality of local files AssertIdentical(localDataDir + filename1, localDataDir + filename2); // and delete local files FileInfo local = new FileInfo(localDataDir + filename1); local.Delete(); local = new FileInfo(localDataDir + filename2); local.Delete(); ftp.Quit(); } catch (Exception ex) { log.Error("ResumeGet() failed", ex); throw; } }
public virtual void ResumePut() { log.Debug("ResumePut()"); try { Connect(); // move to test directory ftp.ChangeWorkingDirectory(testdir); ftp.TransferType = FTPTransferType.BINARY; // put to a random filename string filename = GenerateRandomFilename(); // set up event handler to cancel the transfer cancelled = false; BytesTransferredHandler handler = new BytesTransferredHandler(CancelBytesTransferred); ftp.BytesTransferred += handler; // initiate the put try { ftp.UploadFile(localDataDir + localBinaryFile, filename); Assert.Fail("Should receive cancelled exception"); } catch (FTPTransferCancelledException) { log.Debug("Caught expected exception from cancelled transfer"); } // remove handler now we've cancelled ftp.BytesTransferred -= handler; // should be cancelled - now resume ftp.ResumeTransfer(); // put again - should append ftp.UploadFile(localDataDir + localBinaryFile, filename); // get it back ftp.DownloadFile(localDataDir + filename, filename); // check equality of local files AssertIdentical(localDataDir + localBinaryFile, localDataDir + filename); // finally, just check cancelResume works ftp.CancelResume(); // get it back ftp.DownloadFile(localDataDir + filename, filename); // delete remote file ftp.DeleteFile(filename); // and delete local file FileInfo local = new FileInfo(localDataDir + filename); local.Delete(); ftp.Close(); } catch (Exception ex) { log.Error("ResumePut() failed", ex); throw; } }
public virtual void ResumeGet() { log.Debug("ResumeGet()"); try { Connect(); Login(); // move to test directory ftp.ChDir(testdir); ftp.TransferType = FTPTransferType.BINARY; // put to a random filename string filename1 = GenerateRandomFilename(); // set up event handler to cancel the transfer cancelled = false; BytesTransferredHandler handler = new BytesTransferredHandler(BytesTransferred); ftp.BytesTransferred += handler; // initiate the get log.Debug("Getting '" + remoteBinaryFile + "' to '" + filename1 + "'"); ftp.Get(filename1, remoteBinaryFile); // remove handler for next transfer ftp.BytesTransferred -= handler; // should be cancelled - now resume ftp.Resume(); // get again - should append log.Debug("Resuming '" + remoteBinaryFile + "' to '" + filename1 + "'"); ftp.Get(filename1, remoteBinaryFile); string filename2 = GenerateRandomFilename(); ; // do another get - complete this time ftp.Get(filename2, remoteBinaryFile); // check equality of local files AssertIdentical(filename1, filename2); // and delete local files FileInfo local = new FileInfo(filename1); local.Delete(); local = new FileInfo(filename2); local.Delete(); ftp.Quit(); } catch (Exception ex) { log.Error("ResumeGet() failed", ex); throw ex; } }
public virtual void ResumePut() { log.Debug("ResumePut()"); try { Connect(); Login(); // move to test directory ftp.ChDir(testdir); ftp.TransferType = FTPTransferType.BINARY; // put to a random filename string filename = GenerateRandomFilename(); // set up event handler to cancel the transfer cancelled = false; BytesTransferredHandler handler = new BytesTransferredHandler(BytesTransferred); ftp.BytesTransferred += handler; // initiate the put ftp.Put(localBinaryFile, filename); // remove handler now we've cancelled ftp.BytesTransferred -= handler; // should be cancelled - now resume ftp.Resume(); // put again - should append ftp.Put(localBinaryFile, filename); // get it back ftp.Get(filename, filename); // check equality of local files AssertIdentical(localBinaryFile, filename); // finally, just check cancelResume works ftp.CancelResume(); // get it back ftp.Get(filename, filename); // delete remote file ftp.Delete(filename); // and delete local file FileInfo local = new FileInfo(filename); local.Delete(); ftp.Quit(); } catch (Exception ex) { log.Error("ResumePut() failed", ex); throw ex; } }