public TransferEventArgs(string localFilePath, string remoteFilename, TransferDirection direction, FTPTransferType transferType) { this.localFilePath = localFilePath; this.remoteFilename = remoteFilename; this.direction = direction; this.transferType = transferType; }
public TransferEventArgs(Stream localStream, string remoteFilename, TransferDirection direction, FTPTransferType transferType) { this.localStream = localStream; this.remoteFilename = remoteFilename; this.direction = direction; this.transferType = transferType; }
public TransferEventArgs(byte[] localByteArray, string remoteFilename, TransferDirection direction, FTPTransferType transferType) { this.localByteArray = localByteArray; this.remoteFilename = remoteFilename; this.direction = direction; this.transferType = transferType; }
// // put one file // public void Put(string fileName, // string localpath, // string remotepath, // FTPTransferType FtpType, // bool flatten, // bool createDirsOnDemand, // bool updateOnly) { // // char [] dirseps = {DOS_DIR_SEPERATOR, DIR_SEPERATOR}; // // string localFilePath = String.Empty; // path to 'fileName' locally, relative to 'localpath' // string remoteFilePath = String.Empty; // path to 'fileName' remotely, relative to 'remotepath' // // // convert fileName into relative paths... // if (Path.GetDirectoryName(fileName).Length==0) { // // localFilePath = Path.GetFileName(fileName); // // } else if (Path.GetDirectoryName(fileName).StartsWith(localpath)) { // // // our abs path is longer than localpath, // // so the relative path is simple. // // localFilePath = fileName.Replace(localpath, String.Empty).Remove(0,1); // // } else if (localpath.StartsWith(Path.GetDirectoryName(fileName))) { // // // our abs path is shorter than the localpath // // so our relative path is preceded by '..' references. // // localpath = localpath.Replace(Path.GetDirectoryName(fileName), String.Empty); // // int z = -1; // // z = localpath.IndexOfAny(dirseps); // while( z >-1 ) { // localFilePath += ".."+Path.DirectorySeparatorChar; // localpath = localpath.Remove(z,1); // z = localpath.IndexOfAny(dirseps); // } // localFilePath += Path.GetFileName(fileName); // } // // // mirror the remote file path from the local file path, flattening if requested // if (flatten) { // remoteFilePath = Path.GetFileName(localFilePath); // } else { // remoteFilePath = localFilePath; // } // // remoteFilePath = remoteFilePath.Replace(DOS_DIR_SEPERATOR, DIR_SEPERATOR); // // this.Log(this.LevelLogfiles, " file: {0}", localFilePath); // this.Log(this.LevelExec, " to: {0}", Path.Combine(remotepath, remoteFilePath)); // // if (IsConnected) { // // store the pwd // string pwd = PWD; // // if (this.Exec) { // // change to the requested directory, creating paths as required && requested // string[] dirs = Path.GetDirectoryName(remoteFilePath).Split(dirseps); // foreach(string dir in dirs) { // CWD(dir, createDirsOnDemand); // } // } // if (updateOnly // && (DateTime.Compare(_client.ModTime(Path.GetFileName(remoteFilePath)), // (new FileInfo(fileName)).LastWriteTime // )>=0 // ) // ) { // this.Log(this.LevelLogfiles, "Remote file is newer."); // } else { // this.Log(Level.Verbose, "Putting the file as '{0}'", FtpType); // _client.TransferType = FtpType; // _client.Put(fileName, Path.GetFileName(remoteFilePath)); // } // // if (PWD!=pwd) { // this.Log(Level.Verbose, "Restoring the remote dir to {0}", pwd); // CWD_Quiet(pwd); // } // } // } // // // get one file from the PWD to a localpath (PWD is arranged in Get.TransferFiles // public void Get(string fileName, // string localpath, // string remotepath, // FTPTransferType FtpType, // bool flatten, // bool createDirsOnDemand, // bool updateOnly) { // // // woohoo! the remote parsing works for two test-cases! // // if (RPath.IsPathRooted(remotepath)) { // // strip the initial directoryseperatorchar off // // this converts a remotepath rooted in the remote filesystem root // // to a local path relative to the local-dir attribute. // remotepath = remotepath.Remove(0,1); // } // // DirectoryInfo dirInfo = new DirectoryInfo(Path.Combine(localpath, remotepath)); // // if (flatten) { // dirInfo = new DirectoryInfo(localpath); // } // // this.Log(this.LevelLogfiles, " file: {0}", RPath.Combine(PWD,fileName)); // this.Log(this.LevelExec, " to: {0}", Path.Combine(dirInfo.FullName, fileName)); //// this.Log(this.LevelExec, "Getting {0}", fileName); //// this.Log(Level.Verbose, " from {0}", PWD); //// this.Log(this.LevelExec, " to {0}",dirInfo.FullName); // // if (IsConnected) { // // if (!dirInfo.Exists) { // if (!createDirsOnDemand) { // throw new FTPException("Local directory "+dirInfo.FullName+" does not exist to receive incoming FTP transfer."); // } // try { // dirInfo.Create(); // } catch (Exception ex) { // throw new FTPException("Local directory "+dirInfo.FullName+" could not be created to receive incoming FTP transfer: ", ex.Message); // } // } // _client.Get(Path.Combine(dirInfo.FullName,fileName), fileName); // } // } /// <summary>Download one file</summary> /// <param name="FileName">Download this filename</param> /// <param name="FtpType">using ascii or binary</param> private void downloadFile(string FileName, FTPTransferType FtpType) { _connection.Get(Path.GetFileName(FileName), Path.GetDirectoryName(FileName), ".", FtpType, false, false, false); // string onlyFileName = EMPTY_STRING; // string localRemoteFile = EMPTY_STRING; // string downloadTo = EMPTY_STRING; // FileSet workingFileset = null; // // if (FTPTransferType.ASCII == FtpType) { // workingFileset = _downloadAscii; // } else { // workingFileset = _downloadBinary; // } // if // FileInfo fi = new FileInfo(FileName); // onlyFileName = fi.Name; // fi = null; // // if (!_remotePath.Equals(EMPTY_STRING)) { // if (_remotePath.EndsWith(DIR_SEPERATOR.ToString())) { // localRemoteFile = _remotePath + onlyFileName; // } else { // localRemoteFile = _remotePath + DIR_SEPERATOR + onlyFileName; // } // if // fi = null; // } // if // // if (!workingFileset.BaseDirectory.FullName.EndsWith(DIR_SEPERATOR.ToString()) && // !workingFileset.BaseDirectory.FullName.EndsWith(DOS_DIR_SEPERATOR.ToString())) { // downloadTo = workingFileset.BaseDirectory.FullName.Replace("\\", "/") + DIR_SEPERATOR + onlyFileName; // } else { // downloadTo = workingFileset.BaseDirectory.FullName.Replace("\\", "/") + onlyFileName; // } // if // // this.Log(Level.Verbose, "Downloading file {0} to {1}", localRemoteFile, downloadTo); // // _client.TransferType = FtpType; // _client.Get(downloadTo, localRemoteFile); // //_ftpConn.GetFile(localRemoteFile, downloadTo, FtpType); return; }
/// <summary>Upload one file</summary> /// <param name="FileName">the file to upload</param> /// <param name="FtpType">use this type (ascii/binary)</param> private void uploadFile(string FileName, FTPTransferType FtpType) { _connection.Put(Path.GetFileName(FileName), Path.GetDirectoryName(FileName), "", FtpType, false, false, false); // // string localRemoteFile = EMPTY_STRING; // if (!_remotePath.Equals(EMPTY_STRING)) { // FileInfo fi = new System.IO.FileInfo(FileName); // if (!fi.Exists) { // this.Log(Level.Verbose, "Upload aborted: file does not exist"); // return; // } // if // if (_remotePath.EndsWith(DIR_SEPERATOR.ToString())) { // localRemoteFile = _remotePath + fi.Name; // } else { // localRemoteFile = _remotePath + DIR_SEPERATOR + fi.Name; // } // if // fi = null; // } else { // FileInfo fi = new System.IO.FileInfo(FileName); // if (!fi.Exists) { // this.Log(Level.Verbose, "Upload aborted: file does not exist"); // return; // } // if // localRemoteFile = fi.Name; // fi = null; // } // if // // this.Log(Level.Verbose, "Uploading file {0} to {1}", FileName, localRemoteFile); // _client.TransferType = FtpType; // _client.Put(localRemoteFile, FileName); // //_ftpConn.SendFile(FileName, localRemoteFile, FtpType); return; }
// put one file public void Put(string fileName, string localpath, string remotepath, FTPTransferType FtpType, bool flatten, bool createDirsOnDemand, bool updateOnly) { char [] dirseps = {Path.DirectorySeparatorChar, RPath.DirectorySeparatorChar}; string localFilePath = String.Empty; // path to 'fileName' locally, relative to 'localpath' string remoteFilePath = String.Empty; // path to 'fileName' remotely, relative to 'remotepath' // convert fileName into relative paths... if (Path.GetDirectoryName(fileName).Length==0) { localFilePath = Path.GetFileName(fileName); } else if (Path.GetDirectoryName(fileName).StartsWith(localpath)) { // our abs path is longer than localpath, // so the relative path is simple. localFilePath = fileName.Replace(localpath, String.Empty).Remove(0,1); } else if (localpath.StartsWith(Path.GetDirectoryName(fileName))) { // our abs path is shorter than the localpath // so our relative path is preceded by '..' references. localpath = localpath.Replace(Path.GetDirectoryName(fileName), String.Empty); int z = -1; z = localpath.IndexOfAny(dirseps); while( z >-1 ) { localFilePath += ".."+Path.DirectorySeparatorChar; localpath = localpath.Remove(z,1); z = localpath.IndexOfAny(dirseps); } localFilePath += Path.GetFileName(fileName); } // mirror the remote file path from the local file path, flattening if requested if (flatten) { remoteFilePath = Path.GetFileName(localFilePath); } else { remoteFilePath = localFilePath; } remoteFilePath = remoteFilePath.Replace(Path.DirectorySeparatorChar, RPath.DirectorySeparatorChar); _task.Log(_task.LevelLogfiles, " file: {0}", localFilePath); _task.Log(_task.LevelExec, " to: {0}", Path.Combine(remotepath, remoteFilePath)); if (IsConnected) { // store the pwd string pwd = PWD; if (_task.Exec) { // change to the requested directory, creating paths as required && requested string[] dirs = Path.GetDirectoryName(remoteFilePath).Split(dirseps); foreach(string dir in dirs) { CWD(dir, createDirsOnDemand); } } if (updateOnly && (DateTime.Compare(_client.ModTime(Path.GetFileName(remoteFilePath)), (new FileInfo(fileName)).LastWriteTime )>=0 ) ) { _task.Log(_task.LevelLogfiles, "Remote file is newer."); } else { _task.Log(Level.Verbose, "Putting the file as '{0}'", FtpType); _client.TransferType = FtpType; _client.Put(fileName, Path.GetFileName(remoteFilePath)); } if (PWD!=pwd) { _task.Log(Level.Verbose, "Restoring the remote dir to {0}", pwd); CWD(pwd); } } }
// get one file from the PWD to a localpath (PWD is arranged in Get.TransferFiles public void Get(string fileName, string localpath, string remotepath, FTPTransferType FtpType, bool flatten, bool createDirsOnDemand, bool updateOnly) { // woohoo! the remote parsing works for two test-cases! if (RPath.IsPathRooted(remotepath)) { // strip the initial directoryseperatorchar off // this converts a remotepath rooted in the remote filesystem root // to a local path relative to the local-dir attribute. remotepath = remotepath.Remove(0,1); } DirectoryInfo dirInfo = new DirectoryInfo(Path.Combine(localpath, remotepath)); if (flatten) { dirInfo = new DirectoryInfo(localpath); } _task.Log(_task.LevelLogfiles, " file: {0}", RPath.Combine(PWD,fileName)); _task.Log(_task.LevelExec, " to: {0}", Path.Combine(dirInfo.FullName, fileName)); // this.Log(this.LevelExec, "Getting {0}", fileName); // this.Log(Level.Verbose, " from {0}", PWD); // this.Log(this.LevelExec, " to {0}",dirInfo.FullName); if (IsConnected) { if (!dirInfo.Exists) { if (!createDirsOnDemand) { throw new FTPException("Local directory "+dirInfo.FullName+" does not exist to receive incoming FTP transfer."); } try { dirInfo.Create(); } catch (Exception ex) { throw new FTPException("Local directory "+dirInfo.FullName+" could not be created to receive incoming FTP transfer: ", ex.Message); } } _client.Get(Path.Combine(dirInfo.FullName,fileName), fileName); } }
public void SetTransferType(FTPTransferType TranType) { _Ftp.TransferType = TranType; }
/// <summary> /// Instance initializer. Sets formatter to GMT. /// </summary> private void InitBlock() { log = Logger.GetLogger("FTPClient"); transferType = FTPTransferType.ASCII; connectMode = FTPConnectMode.PASV; controlPort = FTPControlSocket.CONTROL_PORT; }
public FTPClient() { this.dirEmptyStrings = new DirectoryEmptyStrings(); this.transferCompleteStrings = new TransferCompleteStrings(); this.fileNotFoundStrings = new FileNotFoundStrings(); this.modtimeFormats = new string[] { "yyyyMMddHHmmss", "yyyyMMddHHmmss'.'f", "yyyyMMddHHmmss'.'ff", "yyyyMMddHHmmss'.'fff" }; this.control = null; this.data = null; this.timeout = 0x1d4c0; this.noOperationInterval = 0; this.strictReturnCodes = false; this.cancelTransfer = false; this.transferNotifyListings = false; this.resume = false; this.deleteOnFailure = true; this.mdtmSupported = true; this.sizeSupported = true; this.resumeMarker = 0L; this.showHiddenFiles = false; this.monitorInterval = 0x1000L; this.transferBufferSize = 0x1000; this.parserCulture = CultureInfo.InvariantCulture; this.fileFactory = new EnterpriseDT.Net.Ftp.FTPFileFactory(); this.transferType = FTPTransferType.ASCII; this.connectMode = FTPConnectMode.PASV; this.synchronizePassiveConnections = false; this.activePortRange = new PortRange(); this.activeIPAddress = null; this.controlPort = -1; this.remoteHost = null; this.autoPassiveIPSubstitution = false; this.closeStreamsAfterTransfer = true; this.controlEncoding = null; this.dataEncoding = null; this.throttler = null; this.InitBlock(); }
private void InitBlock() { this.log = Logger.GetLogger("FTPClient"); this.transferType = FTPTransferType.ASCII; this.connectMode = FTPConnectMode.PASV; this.controlPort = 0x15; }
/// <summary> /// Create an FTPConnection using the given FTP client. /// </summary> /// <param name="ftpClient"><see cref="FTPClient"/>-instance to use.</param> protected internal FTPConnection(FTPClient ftpClient) { log.Info(VersionDetails.GetVersionDetails(this.GetType())); log.Info("Built: " + BuildTimestamp); lock (instanceCountMutex) { this.instanceNumber = instanceCount++; } this.ftpClient = ftpClient; this.activeClient = ftpClient; this.ftpClient.AutoPassiveIPSubstitution = true; this.ftpClient.BytesTransferred += new BytesTransferredHandler(ftpClient_BytesTransferred); fileTransferType = FTPTransferType.BINARY; ftpClient.CommandSent += new FTPMessageHandler(ftpClient_CommandSent); ftpClient.ReplyReceived += new FTPMessageHandler(ftpClient_ReplyReceived); ftpClient.CommandError += new FTPErrorEventHandler(ftpClient_CommandError); ftpClient.ActivePortRange.PropertyChangeHandler = new PropertyChangedEventHandler(OnActivePortRangeChanged); ftpClient.FileNotFoundMessages.PropertyChangeHandler = new PropertyChangedEventHandler(OnFileNotFoundMessagesChanged); ftpClient.TransferCompleteMessages.PropertyChangeHandler = new PropertyChangedEventHandler(OnFileNotFoundMessagesChanged); ftpClient.DirectoryEmptyMessages.PropertyChangeHandler = new PropertyChangedEventHandler(OnDirectoryEmptyMessagesChanged); }
protected internal FTPConnection(FTPClient ftpClient) { this.components = null; this.log = Logger.GetLogger("FTPConnection"); this.clientLock = new object(); this.useAutoLogin = true; this.areEventsEnabled = true; this.isTransferringData = false; this.guiControl = null; this.haveQueriedForControl = false; this.currentFileSize = -1L; this.useGuiThread = true; this.localDir = null; this.remoteDir = null; this.lastTransferCancel = false; lock (instanceCountMutex) { this.instanceNumber = instanceCount++; } this.ftpClient = ftpClient; this.activeClient = ftpClient; this.ftpClient.AutoPassiveIPSubstitution = true; this.ftpClient.BytesTransferred += new BytesTransferredHandler(this.ftpClient_BytesTransferred); this.fileTransferType = FTPTransferType.BINARY; ftpClient.CommandSent += new FTPMessageHandler(this.ftpClient_CommandSent); ftpClient.ReplyReceived += new FTPMessageHandler(this.ftpClient_ReplyReceived); ftpClient.ActivePortRange.PropertyChangeHandler = new PropertyChangedEventHandler(this.OnActivePortRangeChanged); ftpClient.FileNotFoundMessages.PropertyChangeHandler = new PropertyChangedEventHandler(this.OnFileNotFoundMessagesChanged); ftpClient.TransferCompleteMessages.PropertyChangeHandler = new PropertyChangedEventHandler(this.OnFileNotFoundMessagesChanged); ftpClient.DirectoryEmptyMessages.PropertyChangeHandler = new PropertyChangedEventHandler(this.OnDirectoryEmptyMessagesChanged); }