从SFTP使用SharpSSH获取文件大小 [英] Get file size from SFTP using SharpSSH
问题描述
我从上传本地目录中的zip文件为SFTP使用SharpSSH。一切工作正常。
但是,我想获得我刚刚上传当前文件的文件大小。我这样做的原因是zip文件较大(从45 GB到80 GB),我想,以确保在上传过程中它没有失败或卡住。 。要确保整个拉链上传
I'm uploading a zip file from local directory to SFTP using SharpSSH. Everything works fine. However, I would like to get the file size of the current file I just uploaded. The reason I'm doing this is that the zip file is big (from 45 GB to 80 GB) and I want to make sure that during the upload it didn't fail or stuck. Want to make sure the entire zip is uploaded.
我能得到这样的地方zip文件的文件大小:
I can get the file size of the local zip file like this:
DirectoryInfo di = new DirectoryInfo(yesterdaysArchiveFolder);
FileInfo[] files = di.GetFiles();
foreach (FileInfo f in files)
{
Console.WriteLine("Size of the zip file: " + f.Length);
}
现在,我想做同样的事情,我刚刚上传到文件上传后SFTP完成。
Now, I want to do the same thing for the file I just uploaded to SFTP after the upload is complete.
因为我知道我刚刚上传我创建的文件的名称的的ArrayList
从SFTP把文件。然后我用循环
来得到我刚刚上传的文件。
Since I know the name of the file I just uploaded I create an ArrayList
and put the files from SFTP. I then use for loop
to get the file I just uploaded.
ArrayList FileList = oSftp.GetFileList(_ftpDirectory);
int count = FileList.Count;
Console.WriteLine("Files in SFTP: " + count);
for (int i = 0; i < FileList.Count; i++)
{
if (zipFileName == FileList[i].ToString())
{
Console.WriteLine(FileList[i]);
}
}
的问题是,就像没有属性。长度
来获取该文件的文件的大小?
The problem is that there're no properties like .Length
to get the file size of that file?
有另一种方法,我可以找出文件在远程服务器上的文件大小?
Is there another approach I can take to find out the file size of the file in remote server?
推荐答案
SharpSSH不允许。但随着SharpSSH是开源的,你可以编写它。
SharpSSH does not allow that. But you can code it as SharpSSH is open source.
请参阅我的回答另一个问题SharpSSH的根据日期从SFTP 修改的文件下载
See my answer to another SharpSSH question Download file based on date modified from SFTP.
或使用其他SFTP库:
Or use another SFTP library:
- SSH.NET 有方法
SftpClient.ListDirectory
返回的IEnumerable< SftpFile>
。在SftpFile
的。长度
属性 - 的 WinSCP赋予.NET程序集有方法的
Session.ListDirectory
返回(通过RemoteDirectoryInfo.Files
)的RemoteFileInfo
财产。长度
的(我的WinSCP .NET程序集的作者)的
- SSH.NET has method
SftpClient.ListDirectory
returningIEnumerable<SftpFile>
. TheSftpFile
has.Length
property - WinSCP .NET assembly has method
Session.ListDirectory
returning (viaRemoteDirectoryInfo.Files
) collection ofRemoteFileInfo
with property.Length
(I'm the author of WinSCP .NET assembly)
这篇关于从SFTP使用SharpSSH获取文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!