Hello,
I am implementing a function that is used for cleaning up data. It basically tries to delete a file and then delete its parent folder, as long as it is empty. Therefore, I'm using the following calls in the code below.
Here's what's going on:
System.NotSupportedException: Strings longer than 2147483647 is not supported.
at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestRealPath(String path, Boolean nullOnError)
at Renci.SshNet.SftpClient.Exists(String path)
at Mine.Core.Infrastructure.SftpManager.TryDeleteFileThenParentFolder(String fileFullPath, Int32 id, Type deletionType) in C:\Mine.Core\Infrastructure\SftpManager.cs:line 401
System.NotSupportedException: Strings longer than 2147483647 is not supported.
at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestReadDir(Byte[] handle)
at Renci.SshNet.SftpClient.InternalListDirectory(String path, Action
at Mine.Core.Infrastructure.SftpManager.TryDeleteFileThenParentFolder(String fileFullPath, Int32 id, Type deletionType) in C:\Mine.Core\Infrastructure\SftpManager.cs:line 445
Am I doing something wrong? What's this stuff about the WaitHandle and TimeSpan?
Also, my strings are not long. I even tried changing the code to ChangeDirectory into the folder first and then delete the file. It deletes the file, but again, it still throws that error. Why?
Similarly, I changed the DeleteFolder part to ChangeDirectory into its parent folder and then call the Delete on that subfolder, as well as on the part to ListDirectory.
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// Delete if it exists.
if (_sftpClient.Exists(fileFullPath))
_sftpClient.DeleteFile(fileFullPath);
// Delete parent if it is empty.
int numFilesInParentFolder = 0;
IEnumerable<SftpFile> filesInParentFolder = _sftpClient.ListDirectory(parentFolderPath, null);
using (var e = filesInParentFolder.GetEnumerator())
{
while (e.MoveNext())
numFilesInParentFolder++;
}
if (numFilesInParentFolder == 0)
_sftpClient.DeleteDirectory(parentFolderPath);
I am implementing a function that is used for cleaning up data. It basically tries to delete a file and then delete its parent folder, as long as it is empty. Therefore, I'm using the following calls in the code below.
Here's what's going on:
-
I'm getting an error on the Exists call, but the Delete goes through. I don't understand why. Here is the error from the exception:
System.NotSupportedException: Strings longer than 2147483647 is not supported.
at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestRealPath(String path, Boolean nullOnError)
at Renci.SshNet.SftpClient.Exists(String path)
at Mine.Core.Infrastructure.SftpManager.TryDeleteFileThenParentFolder(String fileFullPath, Int32 id, Type deletionType) in C:\Mine.Core\Infrastructure\SftpManager.cs:line 401
-
The ListDirectory call throws an exception too.
System.NotSupportedException: Strings longer than 2147483647 is not supported.
at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle waitHandle, TimeSpan operationTimeout)
at Renci.SshNet.Sftp.SftpSession.RequestReadDir(Byte[] handle)
at Renci.SshNet.SftpClient.InternalListDirectory(String path, Action
1 listCallback)
at Renci.SshNet.SftpClient.ListDirectory(String path, Action
1 listCallback)at Mine.Core.Infrastructure.SftpManager.TryDeleteFileThenParentFolder(String fileFullPath, Int32 id, Type deletionType) in C:\Mine.Core\Infrastructure\SftpManager.cs:line 445
Am I doing something wrong? What's this stuff about the WaitHandle and TimeSpan?
Also, my strings are not long. I even tried changing the code to ChangeDirectory into the folder first and then delete the file. It deletes the file, but again, it still throws that error. Why?
Similarly, I changed the DeleteFolder part to ChangeDirectory into its parent folder and then call the Delete on that subfolder, as well as on the part to ListDirectory.
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// Delete if it exists.
if (_sftpClient.Exists(fileFullPath))
_sftpClient.DeleteFile(fileFullPath);
// Delete parent if it is empty.
int numFilesInParentFolder = 0;
IEnumerable<SftpFile> filesInParentFolder = _sftpClient.ListDirectory(parentFolderPath, null);
using (var e = filesInParentFolder.GetEnumerator())
{
while (e.MoveNext())
numFilesInParentFolder++;
}
if (numFilesInParentFolder == 0)
_sftpClient.DeleteDirectory(parentFolderPath);