FTP and password file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

FTP and password file?

#1 Post by SIMMS7400 » 25 Oct 2016 08:10

HI Folks -

I have a server I need to transfer files to that requires authentication to log on. What is the best way to achieve this using FTP from batch? I have the password file.

Thanks!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: FTP and password file?

#2 Post by Squashman » 25 Oct 2016 08:21

The FTP command builtin to Windows can be scripted with a script file.

Code: Select all

FTP -s:GetFiles.txt

You can put all your commands in this file that you need to run the FTP. That includes, the server you want to connect to, username, password, files you want to upload or download, etc, etc ,etc
http://ss64.com/nt/ftp.html

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: FTP and password file?

#3 Post by SIMMS7400 » 25 Oct 2016 08:24

Hi Squash -

Ah yes, that's what I currently use:

Code: Select all

::-- Generate FTP Commands File --::

ECHO open %1>%8
ECHO %2>>%8
ECHO %3>>%8
ECHO lcd /D "%4">>%8
ECHO cd "%5">>%8
ECHO binary>>%8
ECHO hash>>%8
ECHO %6 "%7">>%8
ECHO quit>>%8

::-- Launch FTP and Pass Script to it --::

FTP.exe -v -i -s:%8

::-- Delete FTP Commands File on Exit --::

DEL %8
EXIT /B


However, I need to authenticate with a private key when logging in using a *.ppk file i have. Will that work? Perhaps Winscp would be a better option in this situation?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: FTP and password file?

#4 Post by Squashman » 25 Oct 2016 08:36

FTP is FTP. It is not SFTP. If you need to use a key file then you are using SSH, in which case you will need to use a 3rd party utility. It is my understanding that PSFTP and WINSCP can be scripted.

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: FTP and password file?

#5 Post by SIMMS7400 » 25 Oct 2016 18:10

Hi Squash -

I thought so. I needed to leverage WinSCP to do so:

Code: Select all

:File_Transfer
echo ********************************************************>>%logfile%
echo Transfer file to Linux                                   >>%logfile%
echo ********************************************************>>%logfile%

::-- Set Variables for WSCP Process --::

SET WSCP_SRVR=00.11.222.33
SET WSCP_USER=mdm
SET WSCP_PSWD=%MAINPATH%Scripts\NTScripts\ENTYVIO\INFA_DEV_MDM.ppk
SET WSCP_LD=%MAINPATH%%FILEPATH%%EXPORTPATH%
SET WSCP_RD=/home/mdm/s3mdm/
SET WSCP_ITEM=EVIO_Activities.csv
SET WSCP_CMD_FILE=%~n0.tmp

::-- Variables are passed to executable script in a specific order --::

CALL :EXEC_WSCP %WSCP_USER% %WSCP_SRVR% %WSCP_CMD_FILE% %WSCP_PSWD% %WSCP_LD% %WSCP_ITEM% %WSCP_RD%

GOTO S1

:EXEC_WSCP
::-- Generate WinSCP Commands File --::

ECHO open %1@%2>%3
ECHO put %5%6 %7>>%3
ECHO exit>>%3

::-- Launch WinSCP and pass script to it --::

"%WINSCP_PATH%winSCP.exe" /script=%3 /privatekey=%4

::-- Delete WinSCP Commands File when process completes --::

DEL %3

GOTO :EOF


Thanks, Squash!

Post Reply