当前位置: 首页>>代码示例>>C#>>正文


C# FileAction.ToString方法代码示例

本文整理汇总了C#中FileAction.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FileAction.ToString方法的具体用法?C# FileAction.ToString怎么用?C# FileAction.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileAction的用法示例。


在下文中一共展示了FileAction.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PutFile

        /// <summary>
        /// Uploads stream data specified in the inputStream parameter to the remote FTP server.   
        /// </summary>
        /// <param name="inputStream">Any open stream object on the local client machine.</param>
        /// <param name="remotePath">Filename or path and filename of the file stored on the remote FTP server.</param>
        /// <param name="action">The type of put action taken.</param>
        /// <remarks>
        /// The stream is uploaded to the current working directory on the remote server.  The remotePath
        /// parameter is used to specify the path and file name used to store the file on the remote server.
        /// Note that some FTP servers will not accept a full path.  On those systems you must navigate to
        /// the directory you wish to put the file using with the ChangeDirectory() or ChangeDirectoryMultiPath()
        /// method.
        /// </remarks>
        /// <seealso cref="PutFileAsync(string, string, FileAction)"/>
        /// <seealso cref="PutFileUnique(string)"/>
        /// <seealso cref="GetFile(string, string, FileAction)"/>
        /// <seealso cref="GetFileAsync(string, string, FileAction)"/>
        /// <seealso cref="MoveFile"/>
        /// <seealso cref="FxpCopy"/>
        /// <seealso cref="FxpCopyAsync"/>        
        public void PutFile(Stream inputStream, string remotePath, FileAction action)
        {
            if (inputStream == null)
                throw new ArgumentNullException("inputStream");

            if (!inputStream.CanRead)
                throw new ArgumentException("must be readable", "inputStream");

            if (remotePath == null)
                throw new ArgumentNullException("remotePath");

            if (remotePath.Length == 0)
                throw new ArgumentException("must contain a value", "remotePath");

            if (action == FileAction.None)
                throw new ArgumentOutOfRangeException("action", "must contain a value other than 'Unknown'");

            WriteToLog(String.Format("Action='PutFile';Status='TransferBegin';RemotePath='{0}';FileAction='{1}'", remotePath, action.ToString()));

            try
            {
                switch (action)
                {
                    case FileAction.CreateOrAppend:
                        base.TransferData(TransferDirection.ToServer, new FtpRequest(base.CharacterEncoding, FtpCmd.Appe, remotePath), inputStream);
                        break;
                    case FileAction.CreateNew:
                        if (Exists(remotePath))
                        {
                            throw new FtpException("Cannot overwrite existing file when action FileAction.CreateNew is specified.");
                        }
                        base.TransferData(TransferDirection.ToServer, new FtpRequest(base.CharacterEncoding, FtpCmd.Stor, remotePath), inputStream);
                        break;
                    case FileAction.Create:
                        base.TransferData(TransferDirection.ToServer, new FtpRequest(base.CharacterEncoding, FtpCmd.Stor, remotePath), inputStream);
                        break;
                    case FileAction.Resume:
                        //  get the size of the file already on the server (in bytes)
                        long remoteSize = GetFileSize(remotePath);

                        //  if the files are the same size then there is nothing to transfer
                        if (remoteSize == inputStream.Length)
                            return;

                        //  transfer file to the server
                        base.TransferData(TransferDirection.ToServer, new FtpRequest(base.CharacterEncoding, FtpCmd.Stor, remotePath), inputStream, remoteSize);
                        break;
                    case FileAction.ResumeOrCreate:
                        if (Exists(remotePath))
                            PutFile(inputStream, remotePath, FileAction.Resume);
                        else
                            PutFile(inputStream, remotePath, FileAction.Create);
                        break;
                }
            }
            catch (FtpException fex)
            {
                WriteToLog(String.Format("Action='PutFile';Status='TransferError';RemotePath='{0}';FileAction='{1}';ErrorMessage='{2}'", remotePath, action.ToString(), fex.Message));
                throw new FtpDataTransferException(String.Format("An error occurred while putting fileName '{0}'.", remotePath), base.LastResponse, fex);
            }

            WriteToLog(String.Format("Action='PutFile';Status='TransferSuccess';RemotePath='{0}';FileAction='{1}'", remotePath, action.ToString()));
        }
开发者ID:kbrammer,项目名称:FtpClient,代码行数:83,代码来源:FtpClient.cs

示例2: PutFile

        /// <summary>
        /// Uploads stream data specified in the inputStream parameter to the remote FTP server.   
        /// </summary>
        /// <param name="inputStream">Any open stream object on the local client machine.</param>
        /// <param name="remotePath">Filename or path and filename of the file stored on the remote FTP server.</param>
        /// <param name="action">The type of put action taken.</param>
        /// <remarks>
        /// The stream is uploaded to the current working directory on the remote server.  The remotePath
        /// parameter is used to specify the path and file name used to store the file on the remote server.
        /// Note that some FTP servers will not accept a full path.  On those systems you must navigate to
        /// the directory you wish to put the file using with the ChangeDirectory() or ChangeDirectoryMultiPath()
        /// method.
        /// </remarks>
        /// <seealso cref="PutFileAsync(string, string, FileAction)"/>
        /// <seealso cref="PutFileUnique(string)"/>
        /// <seealso cref="GetFile(string, string, FileAction)"/>
        /// <seealso cref="GetFileAsync(string, string, FileAction)"/>
        /// <seealso cref="MoveFile"/>
        /// <seealso cref="FxpCopy"/>
        /// <seealso cref="FxpCopyAsync"/>        
        public void PutFile(Stream inputStream, string remotePath, FileAction action)
        {
            if (inputStream == null)
                throw new ArgumentNullException("inputStream");
            if (!inputStream.CanRead)
                throw new ArgumentException("must be readable", "inputStream");
            if (remotePath == null)
                throw new ArgumentNullException("remotePath");
            if (remotePath.Length == 0)
                throw new ArgumentException("must contain a value", "remotePath");
            if (action == FileAction.None)
                throw new ArgumentOutOfRangeException("action", "must contain a value other than 'Unknown'");

            // set the inputStream if the user supplied it pointing to the end of the stream
            if (inputStream.CanSeek && inputStream.Position == inputStream.Length)
                inputStream.Position = 0;

            WriteToLog(String.Format("Action='PutFile';Status='TransferBegin';RemotePath='{0}';FileAction='{1}'", remotePath, action.ToString()));

            if (IsTranferProgressEventSet() && inputStream.CanSeek)
            {
                // set the transfer size so we can do some calc on percentage completed
                // in the TransferBytes() method of the base class
                SetTransferSize(inputStream.Length);
            }

            try
            {
                switch (action)
                {
                    case FileAction.CreateOrAppend:
                        base.TransferData(TransferDirection.ToServer, new FtpsRequest(base.Encoding, FtpsCmd.Appe, remotePath), inputStream);
                        break;
                    case FileAction.CreateNew:
                        if (Exists(remotePath))
                        {
                            throw new FtpsException("Cannot overwrite existing file when action FileAction.CreateNew is specified.");
                        }
                        base.TransferData(TransferDirection.ToServer, new FtpsRequest(base.Encoding, FtpsCmd.Stor, remotePath), inputStream);
                        break;
                    case FileAction.Create:
                        base.TransferData(TransferDirection.ToServer, new FtpsRequest(base.Encoding, FtpsCmd.Stor, remotePath), inputStream);
                        break;
                    case FileAction.Resume:
                        if (!base.Features.Contains(FtpsCmd.Rest, "STREAM"))
                            throw new FtpsCommandNotSupportedException("Cannot resume file transfer.", "REST STREAM");

                        //  get the file size for a resume
                        long remoteSize;
                        if (!TryGetFileSize(remotePath, out remoteSize))
                            throw new FtpsException("unable to determine file size for resume transfer");

                        //  if the files are the same size then there is nothing to transfer
                        if (remoteSize == inputStream.Length)
                            return;

                        //  transfer file to the server
                        base.TransferData(TransferDirection.ToServer, new FtpsRequest(base.Encoding, FtpsCmd.Stor, remotePath), inputStream, remoteSize);
                        break;
                    case FileAction.ResumeOrCreate:
                        // if the remote file exists then do a resume otherwise do a create
                        if (Exists(remotePath))
                        {
                            PutFile(inputStream, remotePath, FileAction.Resume);
                        }
                        else
                        {
                            PutFile(inputStream, remotePath, FileAction.Create);
                        }
                        break;
                }
            }
            catch (FtpsException fex)
            {
                WriteToLog(String.Format("Action='PutFile';Status='TransferError';RemotePath='{0}';FileAction='{1}';ErrorMessage='{2}'", remotePath, action.ToString(), fex.Message));
                throw new FtpsDataTransferException(String.Format("An error occurred while putting fileName '{0}'.", remotePath), base.LastResponse, fex);
            }

            WriteToLog(String.Format("Action='PutFile';Status='TransferSuccess';RemotePath='{0}';FileAction='{1}'", remotePath, action.ToString()));
        }
开发者ID:cube3power,项目名称:starksoft-aspen,代码行数:100,代码来源:FtpsClient.cs

示例3: GetFile

        /// <summary>
        /// Retrieves a remote file from the FTP server and writes the data to a local file
        /// specfied in the localPath parameter.
        /// </summary>
        /// <remarks>
        /// Note that some FTP servers will not accept a full path.  On those systems you must navigate to
        /// the directory you wish to get the file using with the ChangeDirectory() or ChangeDirectoryMultiPath()
        /// method.
        /// </remarks>
        /// <param name="remotePath">A path and/or file name to the remote file.</param>
        /// <param name="localPath">A fully qualified local path to a file on the local machine.</param>
        /// <param name="action">The type of action to take.</param>
        /// <seealso cref="GetFileAsync(string, string, FileAction)"/>
        /// <seealso cref="PutFile(string, string, FileAction)"/>
        /// <seealso cref="PutFileAsync(string, string, FileAction)"/>
        /// <seealso cref="MoveFile"/>
        /// <seealso cref="FxpCopy"/>
        /// <seealso cref="FxpCopyAsync"/>
        public void GetFile(string remotePath, string localPath, FileAction action)
        {
            if (remotePath == null)
                throw new ArgumentNullException("remotePath");

            if (remotePath.Length == 0)
                throw new ArgumentException("must contain a value", "remotePath");

            if (localPath == null)
                throw new ArgumentNullException("localPath");

            if (localPath.Length == 0)
                throw new ArgumentException("must contain a value", "localPath");

            if (action == FileAction.None)
                throw new ArgumentOutOfRangeException("action", "must contain a value other than 'Unknown'");

            localPath = CorrectLocalPath(localPath);

            WriteToLog(String.Format("Action='GetFile';Status='TransferBegin';LocalPath='{0}';RemotePath='{1}';FileAction='{1}'", localPath, remotePath, action.ToString()));

            FtpRequest request = new FtpRequest(base.CharacterEncoding, FtpCmd.Retr, remotePath);

            try
            {
                switch (action)
                {
                    case FileAction.CreateNew:
                        // create a file stream to stream the file locally to disk that only creates the file if it does not already exist
                        using (Stream localFile = File.Open(localPath, FileMode.CreateNew))
                        {
                            base.TransferData(TransferDirection.ToClient, request, localFile);
                        }
                        break;

                    case FileAction.Create:
                        // create a file stream to stream the file locally to disk
                        using (Stream localFile = File.Open(localPath, FileMode.Create))
                        {
                            base.TransferData(TransferDirection.ToClient, request, localFile);
                        }
                        break;
                    case FileAction.CreateOrAppend:
                        // open the local file
                        using (Stream localFile = File.Open(localPath, FileMode.OpenOrCreate))
                        {
                            // set the file position to the end so that any new data will be appended
                            localFile.Position = localFile.Length;
                            base.TransferData(TransferDirection.ToClient, request, localFile);
                        }
                        break;
                    case FileAction.Resume:
                        using (Stream localFile = File.Open(localPath, FileMode.Open))
                        {
                            //  get the size of the file already on the server (in bytes)
                            long remoteSize = GetFileSize(remotePath);

                            // if the files are the same size then there is nothing to transfer
                            if (localFile.Length == remoteSize)
                                return;

                            base.TransferData(TransferDirection.ToClient, request, localFile, localFile.Length - 1);
                        }
                        break;
                    case FileAction.ResumeOrCreate:
                        if (File.Exists(localPath) && (new FileInfo(localPath)).Length > 0)
                            GetFile(remotePath, localPath, FileAction.Resume);
                        else
                            GetFile(remotePath, localPath, FileAction.Create);
                        break;
                }
            }
            catch (Exception ex)
            {
                WriteToLog(String.Format("Action='GetFile';Status='TransferError';LocalPath='{0}';RemotePath='{1}';FileAction='{1}';ErrorMessage='{2}", localPath, remotePath, action.ToString(), ex.Message));
                throw new FtpException(String.Format("An unexpected exception occurred while retrieving file '{0}'.", remotePath), base.LastResponse, ex);
            }

            WriteToLog(String.Format("Action='GetFile';Status='TransferSuccess';LocalPath='{0}';RemotePath='{1}';FileAction='{1}'", localPath, remotePath, action.ToString()));
        }
开发者ID:kbrammer,项目名称:FtpClient,代码行数:98,代码来源:FtpClient.cs

示例4: GetFile

        /// <summary>
        /// Retrieves a remote file from the FTP server and writes the data to a local file
        /// specfied in the localPath parameter.
        /// </summary>
        /// <remarks>
        /// Note that some FTP servers will not accept a full path.  On those systems you must navigate to
        /// the directory you wish to get the file using with the ChangeDirectory() or ChangeDirectoryMultiPath()
        /// method.
        /// </remarks>
        /// <param name="remotePath">A path and/or file name to the remote file.</param>
        /// <param name="localPath">A fully qualified local path to a file on the local machine.</param>
        /// <param name="action">The type of action to take.</param>
        /// <seealso cref="GetFileAsync(string, string, FileAction)"/>
        /// <seealso cref="PutFile(string, string, FileAction)"/>
        /// <seealso cref="PutFileAsync(string, string, FileAction)"/>
        /// <seealso cref="MoveFile"/>
        /// <seealso cref="FxpCopy"/>
        /// <seealso cref="FxpCopyAsync"/>
        public void GetFile(string remotePath, string localPath, FileAction action)
        {
            if (remotePath == null)
                throw new ArgumentNullException("remotePath");
            if (remotePath.Length == 0)
                throw new ArgumentException("must contain a value", "remotePath");
            if (localPath == null)
                throw new ArgumentNullException("localPath");
            if (localPath.Length == 0)
                throw new ArgumentException("must contain a value", "localPath");
            if (action == FileAction.None)
                throw new ArgumentOutOfRangeException("action", "must contain a value other than 'Unknown'");

            // if the transfer event is being subscribed or this is a resume action then get the file size
            long remoteSize = -1;
            if (IsTranferProgressEventSet() || action == FileAction.Resume)
            {
                // try to get the remote file size 
                TryGetFileSize(remotePath, out remoteSize);
                // set the transfer size so we can do some calc on percentage completed
                // in the TransferBytes() method of the base class
                SetTransferSize(remoteSize);
            }

            localPath = CorrectLocalPath(localPath);

            WriteToLog(String.Format("Action='GetFile';Status='TransferBegin';LocalPath='{0}';RemotePath='{1}';FileAction='{2}'", localPath, remotePath, action.ToString()));

            FtpsRequest request = new FtpsRequest(base.Encoding, FtpsCmd.Retr, remotePath);

            try
            {
                switch (action)
                {
                    case FileAction.CreateNew:
                        // create a file stream to stream the file locally to disk that only creates the file if it does not already exist
                        using (Stream localFile = File.Open(localPath, FileMode.CreateNew))
                        {
                            TransferData(TransferDirection.ToClient, request, localFile);
                        }
                        break;
                    
                    case FileAction.Create:
                        // create a file stream to stream the file locally to disk
                        using (Stream localFile = File.Open(localPath, FileMode.Create))
                        {
                            TransferData(TransferDirection.ToClient, request, localFile);
                        }
                        break;
                    case FileAction.CreateOrAppend:
                        // open the local file
                        using (Stream localFile = File.Open(localPath, FileMode.OpenOrCreate))
                        {
                            // set the file position to the end so that any new data will be appended                        
                            localFile.Position = localFile.Length;
                            TransferData(TransferDirection.ToClient, request, localFile);
                        }
                        break;
                    case FileAction.Resume:
                        if (!base.Features.Contains(FtpsCmd.Rest, "STREAM"))
                            throw new FtpsCommandNotSupportedException("Cannot resume file transfer." ,"REST STREAM");

                        using (Stream localFile = File.Open(localPath, FileMode.Open))
                        {
                            //  make sure we have a valid file size
                            if (remoteSize == -1)
                                throw new FtpsException("unable to determine file size for resume transfer");

                            // if the files are the same size then there is nothing to transfer
                            if (localFile.Length == remoteSize)
                                return;

                            TransferData(TransferDirection.ToClient, request, localFile, localFile.Length - 1);
                        }
                        break;
                    case FileAction.ResumeOrCreate:
                        if (File.Exists(localPath) && (new FileInfo(localPath)).Length > 0)
                            GetFile(remotePath, localPath, FileAction.Resume);
                        else
                            GetFile(remotePath, localPath, FileAction.Create);
                        break;
                }
//.........这里部分代码省略.........
开发者ID:cube3power,项目名称:starksoft-aspen,代码行数:101,代码来源:FtpsClient.cs


注:本文中的FileAction.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。