如何在sftp中查找磁盘空间

本文关键字:查找 磁盘 空间 sftp | 更新日期: 2023-09-27 17:50:10

我是SFTP的新手。我在我的机器(windows 7)上创建了一个位置作为SFTP服务器。我可以通过我的项目上传文件。我用renci。Sshnet dll。现在我试图在SFTP服务器上获得剩余的磁盘空间。我试图通过执行命令来获得空间。但是我被困住了,得到以下错误

System.ArgumentException was unhandled
HResult=-2147024809
Message=Offset and length were out of bounds for the array or count is greater than the    number of elements from index to the end of the source collection.
Source=Renci.SshNet
StackTrace:
   at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle)
   at Renci.SshNet.Channels.Channel.WaitHandle(WaitHandle waitHandle)
   at Renci.SshNet.Channels.ChannelSession.SendExecRequest(String command)
   at Renci.SshNet.SshCommand.BeginExecute(AsyncCallback callback, Object state)
   at LogFileArchive.LogFileArchive.runningcommand() in C:'Utilities'LogFileArchive'Program.cs:line 381
   at LogFileArchive.LogFileArchive.Main(String[] args) in C:'Utilities'LogFileArchive'Program.cs:line 475
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

我试过的源代码如下

using (SshClient sshclient = new SshClient("Host", "Port", "Username", "Password"))
{
    sshclient.Connect();
    var cmd1 = sshclient.RunCommand("echo 1");
    Console.WriteLine(cmd1.Result);
    var cmd2 = sshclient.RunCommand("echo 2");
    Console.WriteLine(cmd2.Result);
    sshclient.Disconnect();
}

请告知这是正确的方法吗?或者给出其他的解

如何在sftp中查找磁盘空间

关于标题问题:
正如在SFTP -检查可用空闲空间中提到的,使用SFTP查询磁盘空间只有一种正式的方法。它不能与SSH一起工作。. NET客户端库(不确定核心FTP服务器)。然后有一个专有的OpenSSH扩展不能与核心FTP服务器一起工作。

关于异常:
您应该从调试异常开始,因为这显然是SSH中的一个错误。NET库,因此很难远程帮助您。该库是开源的,没有依赖关系,因此构建和调试它非常容易。另一方面,异常很可能是由核心FTP服务器返回的一些错误引起的(因为您的代码在对OpenSSH运行时工作正常)。因此,另一种方法是找出为什么(如果)核心FTP服务器错误。

由于它是Windows服务器,您应该尝试使用echo以外的其他命令。注意,echo在Windows上是不可执行的,它是Windows命令行解释器的内部命令。因此,它不能直接用作命令是很常见的(同样的方式,您不能从Start> run 运行echo)。或者尝试使用cmd.exe /c "echo 1"间接运行echo

你也检查了服务器的日志文件吗?

接下来,值得首先尝试在GUI SSH客户机中运行该命令,看看输出是什么。例如,在PuTTY中转到Connection> SSH并在远程命令中指定您的命令(这相当于SshClient.RunCommand)。在第一个Session页面最好选择Never for Close window On exit以确保您可以看到输出