日期:2014-05-17  浏览次数:20998 次

如何将本地文件上传至FTP 并且要求是只读文件
C# code
FileStream input = new FileStream(fileName,FileMode.Open,FileAccess.Read);
            

            if ( resume && input.Length < offset )
            {
                // different file size
                Debug.WriteLine("Overwriting " + fileName, "FtpClient");
                offset = 0;
            }
            else if ( resume && input.Length == offset )
            {
                // file done
                input.Close();
                Debug.WriteLine("Skipping completed " + fileName + " - turn resume off to not detect.", "FtpClient");
                return;
            }

            // dont create untill we know that we need it
            cSocket = this.createDataSocket();

            if ( offset > 0 )
            {
                this.sendCommand( "REST " + offset );
                if ( this.resultCode != 350 )
                {
                    Debug.WriteLine("Resuming not supported", "FtpClient");
                    offset = 0;
                }
            }

            this.sendCommand( "STOR " + Path.GetFileName(fileName) );

            if ( this.resultCode != 125 && this.resultCode != 150 ) throw new FtpException(result.Substring(4));//zonghw

            if ( offset != 0 )
            {
                Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );

                input.Seek(offset,SeekOrigin.Begin);
            }

            Debug.WriteLine( "Uploading file " + fileName + " to " + remotePath, "FtpClient" );

            while ((bytes = input.Read(buffer,0,buffer.Length)) > 0)
            {
                cSocket.Send(buffer, bytes, 0);
            }
   
            input.Close();

            if (cSocket.Connected)
            {
                cSocket.Close();
            }

            this.readResponse();

            if( this.resultCode != 226 && this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));


我现在使用的是这个,用流读取文件,本地能够变成只读的,但是到了FTP文件夹里就不是了

------解决方案--------------------
那是ftp文件夹的权限问题吧