A script built in this way can list a dir and loop over the files downloading the ones you want. If there are any errors you can handle them on a per file level how. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality. Categories in. FTP Upload via command line: Standard upload of a file with a site profile named 'mysite' into a remote directory /upload/. c:”\program files\coreftp\kekoa.co.uk”.
Coreftp download files script - agree
While Shez example above is a good standard way to capture errors from most dos based programs that set ERRORLEVEL and produce output from standard error (2>), kekoa.co.uk out of the box from MS does not set ERRORLEVEL. ERRORLEVEL remains zero whether the script (-s: parameter) succeeds or fails. Redirecting standard error (2>) to "%ERRORFILE%" does not work either as this file will always be a zero byte file (because kekoa.co.uk always returns ERROR_SUCCESS or 0) so only an empty file is created. So the command string:
will never produce the expected results. If we are forced to use the Microsoft FTP client, the best bet is to parse through the %OUTPUTFILE% for certain text strings indicating an error or use a different FTP client other than MS's (like IPSWITCH WS_FTP) that allows for better error trapping. I will follow-up with code examples of how to parse through the %OUTPUTFILE% in a few hours once I finish coding it the brute force way. Thanks!
See my second post below for sample interactive Microsoft FTP session. Parsing example is nextOK what follows is a variation on Martijn S post on kekoa.co.uk here. My solution uses FINDSTR and a separate text file containing search criteria:
Create a text file (FTP_ERR_SEARCH_kekoa.co.uk) containing the following text strings:
Call the following subroutine from your batch/command file:
Sample Microsoft FTP Output
Continuing where I left off Sometimes the best way to find out how something works is to test it yourself rather than rely on the plethora of misinformation found on the internet. So here it goes. The example below shows two different files: kekoa.co.uk and kekoa.co.uk (subtle difference in the name but different just the same). The tst.txt file exists while the tst.tx does not.
Microsoft FTP Example (spacing added for clarity):
Note how the local file system and remote file system respond to the commands above:
for the first put tst.txt command (the file exists on the local file system) we see that the remote server responds by transferring the file.
for the second put tst.tx command (the file kekoa.co.uk does not exist on either system) we see that the local file system responds with the filename kekoa.co.uk and the error message File not found
for the third get tst.tx command (again the file kekoa.co.uk does not exist) we see that the remote file system (actually remote FTP host) responds with the FTP error code, the filename kekoa.co.uk and the error message The system cannot find the file specified.
for the fourth and final get tst.txt command (the file now exists on the remote system) we see that the remote system responds with a successful transfer.
Why all this explanation? It matters when we parse through the file in the previous post to see what the error messages are coming back from MS kekoa.co.uk