本文整理汇总了C#中Renci.SshNet.Sftp.SftpFileAttributes类的典型用法代码示例。如果您正苦于以下问题:C# SftpFileAttributes类的具体用法?C# SftpFileAttributes怎么用?C# SftpFileAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SftpFileAttributes类属于Renci.SshNet.Sftp命名空间,在下文中一共展示了SftpFileAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SftpContextStream
internal SftpContextStream(SftpSession session, string path, FileMode mode, FileAccess access,
SftpFileAttributes attributes)
{
Flags flags = Flags.None;
switch (access)
{
case FileAccess.Read:
flags = Flags.Read;
break;
case FileAccess.Write:
flags = Flags.Write;
break;
case FileAccess.ReadWrite:
flags = Flags.Read | Flags.Write;
break;
}
switch (mode)
{
case FileMode.Append:
flags |= Flags.Append;
break;
case FileMode.Create:
if (attributes == null)
{
flags |= Flags.CreateNew;
}
else
{
flags |= Flags.Truncate;
}
break;
case FileMode.CreateNew:
flags |= Flags.CreateNew;
break;
case FileMode.Open:
break;
case FileMode.OpenOrCreate:
flags |= Flags.CreateNewOrOpen;
break;
case FileMode.Truncate:
flags |= Flags.Truncate;
break;
}
_session = session;
_handle = _session.RequestOpen(path, flags);
_attributes = attributes ?? _session.RequestFStat(_handle);
if (access.HasFlag(FileAccess.Write))
{
_writeBuffer = new byte[WRITE_BUFFER_SIZE];
_writeMode = true;
}
_position = mode != FileMode.Append ? 0 : _attributes.Size;
}
示例2: Arrange
protected void Arrange()
{
var random = new Random();
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_handle = new[] { (byte)random.Next(byte.MinValue, byte.MaxValue) };
_fileAttributes = SftpFileAttributes.Empty;
_bufferSize = (uint)random.Next(0, 1000);
_readBufferSize = (uint)random.Next(0, 1000);
_writeBufferSize = (uint)random.Next(0, 1000);
_sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
var sequence = new MockSequence();
_sftpSessionMock.InSequence(sequence)
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
.Returns(_handle);
_sftpSessionMock.InSequence(sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes);
_sftpSessionMock.InSequence(sequence)
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
.Returns(_readBufferSize);
_sftpSessionMock.InSequence(sequence)
.Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
.Returns(_writeBufferSize);
_sftpSessionMock.InSequence(sequence)
.Setup(p => p.IsOpen)
.Returns(true);
_sftpSessionMock.InSequence(sequence)
.Setup(p => p.RequestClose(_handle));
_sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int)_bufferSize);
}
示例3: GroupCanWriteTest
public void GroupCanWriteTest()
{
SftpFileAttributes target = new SftpFileAttributes(); // TODO: Initialize to an appropriate value
bool expected = false; // TODO: Initialize to an appropriate value
bool actual;
target.GroupCanWrite = expected;
actual = target.GroupCanWrite;
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
示例4: LastAccessTimeTest
public void LastAccessTimeTest()
{
SftpFileAttributes target = new SftpFileAttributes(); // TODO: Initialize to an appropriate value
DateTime expected = new DateTime(); // TODO: Initialize to an appropriate value
DateTime actual;
target.LastAccessTime = expected;
actual = target.LastAccessTime;
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
示例5: GroupIdTest
public void GroupIdTest()
{
SftpFileAttributes target = new SftpFileAttributes(); // TODO: Initialize to an appropriate value
int expected = 0; // TODO: Initialize to an appropriate value
int actual;
target.GroupId = expected;
actual = target.GroupId;
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
示例6: Init
public void Init()
{
var random = new Random();
_protocolVersion = (uint)random.Next(0, int.MaxValue);
_requestId = (uint)random.Next(0, int.MaxValue);
_handle = new byte[random.Next(1, 10)];
random.NextBytes(_handle);
_attributes = SftpFileAttributes.Empty;
_attributesBytes = _attributes.GetBytes();
}
示例7: Init
public void Init()
{
var random = new Random();
_protocolVersion = (uint)random.Next(0, int.MaxValue);
_requestId = (uint)random.Next(0, int.MaxValue);
_encoding = Encoding.Unicode;
_path = random.Next().ToString(CultureInfo.InvariantCulture);
_pathBytes = _encoding.GetBytes(_path);
_attributes = SftpFileAttributes.Empty;
_attributesBytes = _attributes.GetBytes();
}
示例8: SftpFile
/// <summary>
/// Initializes a new instance of the <see cref="SftpFile"/> class.
/// </summary>
/// <param name="sftpSession">The SFTP session.</param>
/// <param name="fullName">Full path of the directory or file.</param>
/// <param name="attributes">Attributes of the directory or file.</param>
internal SftpFile(SftpSession sftpSession, string fullName, SftpFileAttributes attributes)
{
if (attributes == null)
throw new ArgumentNullException("attributes");
if (fullName == null)
throw new ArgumentNullException("fullName");
this._sftpSession = sftpSession;
this.Attributes = attributes;
this.Name = fullName.Substring(fullName.LastIndexOf('/') + 1);
this.FullName = fullName;
}
示例9: ReadAttributes
protected SftpFileAttributes ReadAttributes()
{
var flag = this.ReadUInt32();
long size = -1;
int userId = -1;
int groupId = -1;
uint permissions = 0;
var accessTime = DateTime.MinValue;
var modifyTime = DateTime.MinValue;
IDictionary<string, string> extensions = null;
if ((flag & 0x00000001) == 0x00000001) // SSH_FILEXFER_ATTR_SIZE
{
size = (long)this.ReadUInt64();
}
if ((flag & 0x00000002) == 0x00000002) // SSH_FILEXFER_ATTR_UIDGID
{
userId = (int)this.ReadUInt32();
groupId = (int)this.ReadUInt32();
}
if ((flag & 0x00000004) == 0x00000004) // SSH_FILEXFER_ATTR_PERMISSIONS
{
permissions = this.ReadUInt32();
}
if ((flag & 0x00000008) == 0x00000008) // SSH_FILEXFER_ATTR_ACMODTIME
{
var time = this.ReadUInt32();
accessTime = DateTime.FromFileTime((time + 11644473600) * 10000000);
time = this.ReadUInt32();
modifyTime = DateTime.FromFileTime((time + 11644473600) * 10000000);
}
if ((flag & 0x80000000) == 0x80000000) // SSH_FILEXFER_ATTR_ACMODTIME
{
var extendedCount = this.ReadUInt32();
extensions = this.ReadExtensionPair();
}
var attributes = new SftpFileAttributes(accessTime, modifyTime, size, userId, groupId, permissions, extensions);
return attributes;
}
示例10: Arrange
protected void Arrange()
{
_random = new Random();
_path = _random.Next().ToString(CultureInfo.InvariantCulture);
_handle = new[] {(byte) _random.Next(byte.MinValue, byte.MaxValue)};
_fileAttributes = SftpFileAttributes.Empty;
_bufferSize = (uint) _random.Next(1, 1000);
_readBufferSize = (uint) _random.Next(0, 1000);
_writeBufferSize = (uint) _random.Next(500, 1000);
_data = new byte[(_writeBufferSize * 2) + 15];
_random.NextBytes(_data);
_offset = _random.Next(1, 5);
// to get multiple SSH_FXP_WRITE messages (and verify the offset is updated correctly), we make sure
// the number of bytes to write is at least two times the write buffer size; we write a few extra bytes to
// ensure the buffer is not empty after the writes so we can verify whether Length, Dispose and Flush
// flush the buffer
_count = ((int) _writeBufferSize*2) + _random.Next(1, 5);
_expectedWrittenByteCount = (2 * _writeBufferSize);
_expectedBufferedByteCount = (int)(_count - _expectedWrittenByteCount);
_expectedBufferedBytes = _data.Take(_offset + (int)_expectedWrittenByteCount, _expectedBufferedByteCount);
_sftpSessionMock = new Mock<ISftpSession>(MockBehavior.Strict);
_sequence = new MockSequence();
_sftpSessionMock.InSequence(_sequence)
.Setup(p => p.RequestOpen(_path, Flags.Write | Flags.Truncate, true))
.Returns(_handle);
_sftpSessionMock.InSequence(_sequence).Setup(p => p.RequestFStat(_handle)).Returns(_fileAttributes);
_sftpSessionMock.InSequence(_sequence)
.Setup(p => p.CalculateOptimalReadLength(_bufferSize))
.Returns(_readBufferSize);
_sftpSessionMock.InSequence(_sequence)
.Setup(p => p.CalculateOptimalWriteLength(_bufferSize, _handle))
.Returns(_writeBufferSize);
_sftpSessionMock.InSequence(_sequence)
.Setup(p => p.IsOpen)
.Returns(true);
_sftpSessionMock.InSequence(_sequence)
.Setup(p => p.RequestWrite(_handle, 0, _data, _offset, (int) _writeBufferSize, It.IsAny<AutoResetEvent>(), null));
_sftpSessionMock.InSequence(_sequence)
.Setup(p => p.RequestWrite(_handle, _writeBufferSize, _data, _offset + (int) _writeBufferSize, (int)_writeBufferSize, It.IsAny<AutoResetEvent>(), null));
_sftpFileStream = new SftpFileStream(_sftpSessionMock.Object, _path, FileMode.Create, FileAccess.Write, (int) _bufferSize);
}
开发者ID:sshnet,项目名称:SSH.NET,代码行数:45,代码来源:SftpFileStreamTest_Write_SessionOpen_CountGreatherThanTwoTimesTheWriteBufferSize.cs
示例11: SftpFile
/// <summary>
/// Initializes a new instance of the <see cref="SftpFile"/> class.
/// </summary>
/// <param name="sftpSession">The SFTP session.</param>
/// <param name="fullName">Full path of the directory or file.</param>
/// <param name="attributes">Attributes of the directory or file.</param>
/// <exception cref="ArgumentNullException"><paramref name="sftpSession"/> or <paramref name="fullName"/> is null.</exception>
internal SftpFile(ISftpSession sftpSession, string fullName, SftpFileAttributes attributes)
{
if (sftpSession == null)
throw new SshConnectionException("Client not connected.");
if (attributes == null)
throw new ArgumentNullException("attributes");
if (fullName == null)
throw new ArgumentNullException("fullName");
_sftpSession = sftpSession;
Attributes = attributes;
Name = fullName.Substring(fullName.LastIndexOf('/') + 1);
FullName = fullName;
}
示例12: SetAttributes
/// <summary>
/// Sets the specified <see cref="SftpFileAttributes"/> of the file on the specified path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <param name="fileAttributes">The desired <see cref="SftpFileAttributes"/>.</param>
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
public void SetAttributes(string path, SftpFileAttributes fileAttributes)
{
var fullPath = this._sftpSession.GetCanonicalPath(path);
this._sftpSession.RequestSetStat(fullPath, fileAttributes);
}
示例13: SftpContext
public SftpContext(SftpFileAttributes attributes, bool aDeleteOnCloseWorkaround)
{
_attributes = attributes;
this.deleteOnCloseWorkaround = aDeleteOnCloseWorkaround;
}
示例14: Write
protected void Write(SftpFileAttributes attributes)
{
if (attributes == null)
{
this.Write((uint)0);
return;
}
UInt32 flag = 0;
if (attributes.IsSizeChanged && attributes.IsRegularFile)
{
flag |= 0x00000001;
}
if (attributes.IsUserIdChanged|| attributes.IsGroupIdChanged)
{
flag |= 0x00000002;
}
if (attributes.IsPermissionsChanged)
{
flag |= 0x00000004;
}
if (attributes.IsLastAccessTimeChanged || attributes.IsLastWriteTimeChanged)
{
flag |= 0x00000008;
}
if (attributes.IsExtensionsChanged)
{
flag |= 0x80000000;
}
this.Write(flag);
if (attributes.IsSizeChanged && attributes.IsRegularFile)
{
this.Write((UInt64)attributes.Size);
}
if (attributes.IsUserIdChanged|| attributes.IsGroupIdChanged)
{
this.Write((UInt32)attributes.UserId);
this.Write((UInt32)attributes.GroupId);
}
if (attributes.IsPermissionsChanged)
{
this.Write(attributes.Permissions);
}
if (attributes.IsLastAccessTimeChanged || attributes.IsLastWriteTimeChanged)
{
var time = (uint)(attributes.LastAccessTime.ToFileTime() / 10000000 - 11644473600);
this.Write(time);
time = (uint)(attributes.LastWriteTime.ToFileTime() / 10000000 - 11644473600);
this.Write(time);
}
if (attributes.IsExtensionsChanged)
{
this.Write(attributes.Extensions);
}
}
示例15: RequestSetStat
/// <summary>
/// Performs SSH_FXP_SETSTAT request.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="attributes">The attributes.</param>
internal void RequestSetStat(string path, SftpFileAttributes attributes)
{
SshException exception = null;
using (var wait = new AutoResetEvent(false))
{
var request = new SftpSetStatRequest(this.ProtocolVersion, this.NextRequestId, path, this.Encoding, attributes,
(response) =>
{
exception = this.GetSftpException(response);
wait.Set();
});
this.SendRequest(request);
this.WaitHandle(wait, this._operationTimeout);
}
if (exception != null)
{
throw exception;
}
}