Thank you
It works very well.
// Check & create remote directory
if (!session.FileExists(dirTo))
{
string[] ss = dirTo.Split('/');
string curdir = "";
foreach(string s in ss)
{
curdir += '/' + s;
if (!session.FileExists(curdir))
session.CreateDirectory(curdir);
}
}
call bash -c "[ -d <Path to directory> ] || mkdir <Path to directory>"
Session.FileExists(path)
command works for directories as well. :)
But how can I check if a subdirectory/folder in that SFTP site exists?
Session.FileExists
method.
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("open " + _Host)
process.StandardInput.WriteLine(_UserName)
process.StandardInput.WriteLine(_Password)
Dim ans = process.StandardOutput.ReadLine
While ans <> Nothing
If ans.Contains("Session started.") Then
ans = ans
Exit While
End If
ans = process.StandardOutput.ReadLine
End While
process.StandardInput.WriteLine("cd " + uDestPath)
mkdir
a folder and then write the file.
IF EXIST (winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "cd Pervasive\Production\test\concentra\" "exit") (
winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "cd Pervasive\Production\test\concentra\" "lcd ""C:\Users\naa\Cosmos9_Work\Production\concentra\work\""" "put ""elig_test.20120813.txt""" "exit"
) ELSE (
winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "mkdir Pervasive\Production\test\concentra\" "exit"
)
rem %1 is local directory
rem %2 remote directory
rem %3 is file name
pause
cd "c:\Program Files (x86)\WinSCP"
pause
winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "cd ""%2""" "lcd ""%1""" "put ""%3""" "exit"
pause
echo %errorlevel%
pause
rem IF 2 GEQ 15 echo "bigger"
IF %ERRORLEVEL% == 0 (
Echo No error found
GOTO exit
} ELSE (
GOTO error
)
echo.errorlevel = %errorlevel%
pause
GOTO exit
rem winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "lcd ""C:\Users\naa\Cosmos9_Work\Production\jacob\""" "cd ""Pervasive\Production\test\""" "put ""test1.map.xml""" "exit"
:error
pause
winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "mkdir Pervasive\Production\test\concentra\" "exit"
winscp.com /command "option batch ""off""" "option confirm ""off""" "open ""NAA_FTP_TSL""" "cd ""%2""" "lcd ""%1""" "put ""%3""" "exit"
pause
:exit
option batch on
option confirm off
lcd C:\my_local_files
mkdir 123456
put .\123456\orderconf_1234.xml ./123456/orderconf_1234.xml
exit
123456
already exists, WinSCP gives the error:
Error creating folder '123456'.
Can't create directory: File exists
mkdir my_folder
if my_folder
doesn't exist" on the remote system?