Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Automatic upload with batch file

First, the C:\Program Files (x86)\WinSCP\WinSCP.log log file path is suspicious. Unless you run the batch file as Administrator (what you should not), WinSCP won't have permissions to write to that folder. So it will fail. Use a log path that you have write permissions too.

See also https://winscp.net/eng/docs/troubleshooting#scripting
ClassicCarr

WinSCP Version

Failed to mention. Using 5.21.7 version of WinSCP.
ClassicCarr

Powershell command

Or I can get this powershell command to work but I would like to have it upload all files in the directory and then delete the files. Is it as easy and just replacing the file name new test 2.txt with *.* to upload all files in the directory:

# PowerShell >=7.3
$PSNativeCommandArgumentPassing = "Legacy"

& "C:\Program Files (x86)\WinSCP\WinSCP.com" `
/log="C:\install\log\WinSCP.log" /ini=nul `
/command `
"open ftpes://XXX:Password@ftps.XXXX.com/" `
"lcd `"`"T:\Path`"`"" `
"cd /" `
"put -delete `"`"New test 2.txt`"`"" `
"exit"

$winscpResult = $LastExitCode
if ($winscpResult -eq 0)
{
Write-Host "Success"
}
else
{
Write-Host "Error"
}

exit $winscpResult
ClassicCarr

Automatic upload with batch file

I have created a batch file but it is not uploading to our FTP site. Batch file is such:
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\Program Files (x86)\WinSCP\WinSCP.log" /ini=nul ^
  /command ^
    "open ftpes://LOGINID:Password@ftps.xxx.com/" ^
    "lcd ""T:\directory housing files""" ^
    "cd /" ^
    "put test.txt" ^
    "put test2.txt" ^
    "put trial.txt" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit /b %WINSCP_RESULT%

It will not ftp the files to the site. Obviously I have saved it as a batch file. Also, I have changed the sensitive information above. I would like to do an upload of all files in the directory and delete the files when done.

Any help on the syntax of the batch file? I have winscp installed in the default directory so the path to the program isn't an issue.

Thanks in advance for any assistance.