使用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[^]