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

Author Message
kathryn
[View user's profile]

Joined: 2012-07-30
Posts: 3
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!!!
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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
_________________
Martin Prikryl
kathryn
[View user's profile]

Joined: 2012-07-30
Posts: 3
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;)
prikryl 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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
kathryn wrote:
What do you mean by workng directory?

https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx

But try the .NET assembly anyway :)
kathryn
[View user's profile]

Joined: 2012-07-30
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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License