@@ -18,6 +18,8 @@ namespace Renci.SshNet
18
18
/// </summary>
19
19
public class SftpClient : BaseClient
20
20
{
21
+ private static readonly Encoding Utf8NoBOM = new UTF8Encoding ( false , true ) ;
22
+
21
23
/// <summary>
22
24
/// Holds the <see cref="ISftpSession"/> instance that is used to communicate to the
23
25
/// SFTP server.
@@ -1006,6 +1008,9 @@ public SftpFileSytemInformation GetStatus(string path)
1006
1008
/// <exception cref="SshConnectionException">Client is not connected.</exception>
1007
1009
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
1008
1010
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1011
+ /// <remarks>
1012
+ /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM)
1013
+ /// </remarks>
1009
1014
public void AppendAllLines ( string path , IEnumerable < string > contents )
1010
1015
{
1011
1016
CheckDisposed ( ) ;
@@ -1057,6 +1062,9 @@ public void AppendAllLines(string path, IEnumerable<string> contents, Encoding e
1057
1062
/// <exception cref="SshConnectionException">Client is not connected.</exception>
1058
1063
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
1059
1064
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1065
+ /// <remarks>
1066
+ /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
1067
+ /// </remarks>
1060
1068
public void AppendAllText ( string path , string contents )
1061
1069
{
1062
1070
using ( var stream = AppendText ( path ) )
@@ -1088,15 +1096,16 @@ public void AppendAllText(string path, string contents, Encoding encoding)
1088
1096
/// </summary>
1089
1097
/// <param name="path">The path to the file to append to.</param>
1090
1098
/// <returns>
1091
- /// A <see cref="StreamWriter"/> that appends UTF-8 encoded text to an existing file.
1099
+ /// A <see cref="StreamWriter"/> that appends text to a file using UTF-8 encoding without a
1100
+ /// Byte-Order Mark (BOM).
1092
1101
/// </returns>
1093
1102
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
1094
1103
/// <exception cref="SshConnectionException">Client is not connected.</exception>
1095
1104
/// <exception cref="SftpPathNotFoundException"><paramref name="path"/> was not found on the remote host.</exception>
1096
1105
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1097
1106
public StreamWriter AppendText ( string path )
1098
1107
{
1099
- return AppendText ( path , Encoding . UTF8 ) ;
1108
+ return AppendText ( path , Utf8NoBOM ) ;
1100
1109
}
1101
1110
1102
1111
/// <summary>
@@ -1167,10 +1176,12 @@ public SftpFileStream Create(string path, int bufferSize)
1167
1176
/// </summary>
1168
1177
/// <param name="path">The file to be opened for writing.</param>
1169
1178
/// <returns>
1170
- /// A <see cref="StreamWriter"/> that writes to the specified file using UTF-8 encoding.
1179
+ /// A <see cref="StreamWriter"/> that writes text to a file using UTF-8 encoding without
1180
+ /// a Byte-Order Mark (BOM).
1171
1181
/// </returns>
1172
1182
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
1173
1183
/// <exception cref="SshConnectionException">Client is not connected.</exception>
1184
+ /// <exception cref="SftpPathNotFoundException">The specified path is invalid, or its directory was not found on the remote host.</exception>
1174
1185
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1175
1186
/// <remarks>
1176
1187
/// <para>
@@ -1182,7 +1193,7 @@ public SftpFileStream Create(string path, int bufferSize)
1182
1193
/// </remarks>
1183
1194
public StreamWriter CreateText ( string path )
1184
1195
{
1185
- return CreateText ( path , Encoding . UTF8 ) ;
1196
+ return CreateText ( path , Utf8NoBOM ) ;
1186
1197
}
1187
1198
1188
1199
/// <summary>
@@ -1586,6 +1597,9 @@ public void WriteAllBytes(string path, byte[] bytes)
1586
1597
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1587
1598
/// <remarks>
1588
1599
/// <para>
1600
+ /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
1601
+ /// </para>
1602
+ /// <para>
1589
1603
/// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
1590
1604
/// </para>
1591
1605
/// <para>
@@ -1594,7 +1608,7 @@ public void WriteAllBytes(string path, byte[] bytes)
1594
1608
/// </remarks>
1595
1609
public void WriteAllLines ( string path , IEnumerable < string > contents )
1596
1610
{
1597
- WriteAllLines ( path , contents , Encoding . UTF8 ) ;
1611
+ WriteAllLines ( path , contents , Utf8NoBOM ) ;
1598
1612
}
1599
1613
1600
1614
/// <summary>
@@ -1607,6 +1621,9 @@ public void WriteAllLines(string path, IEnumerable<string> contents)
1607
1621
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1608
1622
/// <remarks>
1609
1623
/// <para>
1624
+ /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM).
1625
+ /// </para>
1626
+ /// <para>
1610
1627
/// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
1611
1628
/// </para>
1612
1629
/// <para>
@@ -1615,7 +1632,7 @@ public void WriteAllLines(string path, IEnumerable<string> contents)
1615
1632
/// </remarks>
1616
1633
public void WriteAllLines ( string path , string [ ] contents )
1617
1634
{
1618
- WriteAllLines ( path , contents , Encoding . UTF8 ) ;
1635
+ WriteAllLines ( path , contents , Utf8NoBOM ) ;
1619
1636
}
1620
1637
1621
1638
/// <summary>
@@ -1682,10 +1699,10 @@ public void WriteAllLines(string path, string[] contents, Encoding encoding)
1682
1699
/// <exception cref="ArgumentNullException"><paramref name="path"/> is <b>null</b>.</exception>
1683
1700
/// <exception cref="SshConnectionException">Client is not connected.</exception>
1684
1701
/// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception>
1702
+ /// <remarks>
1685
1703
/// <para>
1686
- /// If the target file already exists, it is overwritten. It is not first truncated to zero bytes .
1704
+ /// The characters are written to the file using UTF-8 encoding without a Byte-Order Mark (BOM) .
1687
1705
/// </para>
1688
- /// <remarks>
1689
1706
/// <para>
1690
1707
/// If the target file already exists, it is overwritten. It is not first truncated to zero bytes.
1691
1708
/// </para>
0 commit comments