SharpSSH 进度和重命名
使用该库连接到远程服务器并复制文件。我的流程运行得相当好,但有一些较小的事情我似乎无法解决,因为该库的文档相当薄弱。
我有两个日常工作。一个使用 Tamir.SharpSsh 类,另一个使用 Tamir.SharpSsh.jsch 类。
使用 Tamir.SharpSsh 类,我可以将文件从本地服务器复制到远程服务器并利用 pogress 事件。我无法做的是确定远程服务器上的特定文件 /Report/data.txt 是否存在于服务器上。如果存在或不存在,我需要采取不同的操作。另外我如何重命名远程服务器上的文件。我尝试过将 SshExec 与“重命名”、“rn”和“mv”命令一起使用,但它似乎不起作用。
使用 Tamir.SharpSsh.jsch 我可以将文件从本地服务器复制到远程服务器。我还可以重命名远程服务器上的文件。我对这个类不能做的是利用进度事件来跟踪复制进度。另外,我似乎无法找到一种好方法来测试服务器上是否存在特定文件。我想出的方法很粗糙,我能想出的唯一测试方法就是使用
Dim c As ChannelSftp Dim vct As Tamir.SharpSsh.java.util.Vector = c.ls(sRemoteFile) Dim cnt As Integer = vct.Count
当一个或多个文件存在时我得到一个计数没有问题。当没有文件时,会抛出异常。
不管怎样,我有日常工作,只是一些我需要帮助的小事情。
蒂亚 AGP
Using the library to connect to a remote server and copy a file. I have the process working fairly well but have some smaller things which I cant seem to resolve as documentation for the library is fairly thin.
I have two routines working. One using the Tamir.SharpSsh class and the other using the Tamir.SharpSsh.jsch class.
Using the Tamir.SharpSsh class I am able to copy the file from the local server to the remote server and tap into the pogress event. What I can't do is determine if a particular file on the remote server say /Report/data.txt exists on the server. I need to take different actions if it exists or if doesn't exist. Also how would I rename a file on the remote server. Ive tried using SshExec with a 'rename', 'rn', and 'mv' command and it doesn't seem to work.
Using the Tamir.SharpSsh.jsch I can copy the file from the local server to the remote server. I can also rename the file on the remote server. What I cant do with this class is to tap into the progress event to keep track of the copy progress. Also I cant seem to find a good way to test to see if a particular file exists on the server. What I have come up with is crude and the only way that I could come up with to test and that is to use
Dim c As ChannelSftp Dim vct As Tamir.SharpSsh.java.util.Vector = c.ls(sRemoteFile) Dim cnt As Integer = vct.Count
When one or more file exists I get a count no problem. When there is no file then an exception is thrown.
Anyway, I have the routines working its just some minor things I need help with.
tia
AGP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用要检查是否存在的文件的路径调用
Tamir.SharpSsh.Sftp.GetFile
方法(例如 C# 中的示例,抱歉):通过使用这个库 - 就像缺少
GetFileInfo
方法或递归 Gets 和 Puts 一样。但总的来说,它完成了工作。简单的事实是,Tamir.SharpSsh 无法远程重命名文件 - 它只是没有实现该功能。您可以购买具有更多功能的更好的库,例如:
或者您可以扩展 SharpSsh,因为它是开源的。
You can call the
Tamir.SharpSsh.Sftp.GetFile
method using the path of the file you want to check exists (example in C#, sorry):I have also noticed a few other issues through my use of this library - like a lack of a
GetFileInfo
method or recursive Gets and Puts. But overall it get the job done.The simple fact is, Tamir.SharpSsh can't rename a file remotely - it just does not implement that functionality. You can purchase a better library that has far more features, such as:
or you could extend SharpSsh, since it is open source.
您的问题是由于 SFTP 协议的限制造成的。
- 要检查文件是否存在,请尝试返回该文件的属性;
- 大多数服务器目前不支持文件重命名。
Your issues are because of limitations of SFTP protocol.
- to check file existence, try to return attributes of that file;
- most servers don't support file renaming for now.
是的,我尝试了与 Tamir.SharpSsh.jsch 类似的方法,但对我来说,你必须捕获异常才能检测文件不存在,这似乎很奇怪。这是我发布后所做的:
yeah I tried something similar with Tamir.SharpSsh.jsch but it seems odd to me that you have to catch the exception to detect non-existence of a file. here is what i did after I posted: