使用WinScp检查远程服务器中是否存在文件夹/目录 [英] Check If Folder/Directory Exists in Remote Server Using WinScp

查看:1811
本文介绍了使用WinScp检查远程服务器中是否存在文件夹/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim uDestPath As String = AppSettings.Get("UnixPath")
Dim uWinScpPath As String = AppSettings.Get("WINscpPath")

Dim oDecrypt As New ConnObjDecrypt.Decryptor
Dim oUnixConStr As Array = oDecrypt.DecryptConnectionString(AppSettings("UnixConString")).Split(";")
Dim sFTPServer As String = ReturnValue(oUnixConStr.GetValue(0))
Dim _Host As String = AppSettings.Get("UnixHost")
Dim _UserName As String = ReturnValue(oUnixConStr.GetValue(1))
Dim _Password As String = ReturnValue(oUnixConStr.GetValue(2))

Dim logname As String = Path.ChangeExtension(Path.GetTempFileName, "xml")

''create the required startinfo for WinSCP to run in background.
Dim startInfo As New ProcessStartInfo
startInfo.FileName = uWinScpPath
startInfo.RedirectStandardInput = True
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
startInfo.CreateNoWindow = True
startInfo.WindowStyle = ProcessWindowStyle.Hidden

''Start WINscp
Dim process As New Process
process.StartInfo = startInfo
process.Start()

''run the commands
''Open sftp connection with User and Password validations
process.StandardInput.WriteLine("option batch abort")
process.StandardInput.WriteLine("option confirm off")
process.StandardInput.WriteLine("open " + _Host)
process.StandardInput.WriteLine(_UserName)
process.StandardInput.WriteLine(_Password)

process.StandardInput.WriteLine("cd " + uDestPath)



上面的代码为我工作.

但是无法检查远程服务器中是否存在文件夹.

我的过程是,我将检查远程服务器中是否存在某个文件夹(目录).
如果该文件夹(目录)存在,我将更新其中的文件吗?
如果folder(Directory)不存在,那么我将创建.



Above code is working for me.

But could not do checking if folder exists in the Remote Server.

My process would be is, I''ll check if a certain folder(Directory) exists in the Remote Server.
If the folder(Directory) exists, I''ll update files inside it?
if folder(Directory) does not exists, then I will create.

How can I check if folder exists in the Remote Server Using Winscp?

推荐答案

使用System.IO名称空间的Directory.Exists方法!

http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx#Y693 [ ^ ]
Use Directory.Exists method of System.IO namespace!

http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx#Y693[^]


这篇关于使用WinScp检查远程服务器中是否存在文件夹/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆