Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
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)


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?
Posted

1 solution

Use Directory.Exists method of System.IO namespace!

http://msdn.microsoft.com/en-us/library/system.io.directory.exists.aspx#Y693[^]
 
Share this answer
 
Comments
Alan Tuscano 27-Sep-12 1:06am    
Hi Kuthuparakkal,

I use WINscp or FileZilla to access the remote "path/directory". I've tried Directory.Exists and it can't locate such "path/directory" in the remote server.
Kuthuparakkal 27-Sep-12 1:56am    
Use RemoteDirectoryInfo
Dim directory As RemoteDirectoryInfo = session.ListDirectory("yourDirectoryPath")
then check if you get onject as "Nothing" or not
ref:
http://winscp.net/eng/docs/library_remotedirectoryinfo

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900