WINSCP script, batch file, and C# code don't work together..

Advertisement

kathryn
Joined:
Posts:
3

WINSCP script, batch file, and C# code don't work together..

Hi,

I am new to WINSCP, please help.

I have a script for uploading a file, then use a batch file to run that script. The batch file also archive the file locally if uploading is successful, or put the file into a failed folder if uploading is failed.
Both the script.txt and the batch file are under the WINSCP directory, and when double click the batch file, it runs successfully.

I also have a C# Windows form application, when a button is clicked the batch file will be invoked to upload that file too. I don't know why, but the file always end up failed to upload, and goes to the failed folder. It tells me that the batch file is executed, just the uploading using WINSCP failed. I attched the script, batch, and part of the code below:

C# code: System.Diagnostics.Process.Start(batPath);//batPath is @"C:\PROGRA~1\WINSCP\TNDOS.bat"

Script.txt:
option batch abort
option confirm off
# open stored session
open TNStateUpload
put E:\Export\TNDOT\*.*
close
exit

Batch file:
winscp.com /script=script.txt
if errorlevel 1 goto error

echo Upload succeeded, moving local files
move E:\Export\TNDOT\*.* E:\Export\Archive\
goto end

:error
echo Upload failed, moving local files
move E:\Export\TNDOT\*.* E:\Export\Failed\

:end


I will be waiting for answers, thanks to everyone takes time to read this post and trying to help.

Thanks!!!

Reply with quote

Advertisement

kathryn
Joined:
Posts:
3

Re: WINSCP script, batch file, and C# code don't work together..

Thank you! What do you mean by workng directory? I can double click the bat file in that directory and the bat runs fine.
I will try the WinSCP.NET assembly.
Thank you so much;)

martin wrote:

My guess is that you do not execute the TNDOS.bat with C:\PROGRA~1\WINSCP\ as working directory, so it won't find winscp.com.
Anyway, I recommend you use WinSCP .NET assembly instead:
https://winscp.net/eng/docs/library

Reply with quote

kathryn
Joined:
Posts:
3

I tried to use the .NET assembly, but because I am using framework 1.1, I got errors...now I need to focus on the working directory solution.
Do you mean that I need to set the working directory in the c# code to the WINSCP dir so the bat can run? Let me try that;)

Thanks!!!
Kathryn

Reply with quote

Advertisement

You can post new topics in this forum