Creating Schedule to transfer CSV files from WinSCP to an FTP [closed]

1

I need to transfer CSV extension files that are in a folder on my Linux server (accessible via WinSCP via Windows) to an FTP. For this, it is necessary to create a schedule that makes this transfer daily.

I found this that involves creating and using schedules using WinSCP, but it got me a little vague.

What could I do in this case?

    
asked by anonymous 07.05.2015 / 19:40

1 answer

0

You certainly know PuTTY , it has a utility called PSCP , which does file transfer via SFTP, or SSH. It can use a session created inside the PuTTY for the connection, something like this:

%Path_Putty%\pscp.exe arquivo.csv SESSAO_SSH:/home/user/

This will transfer the .csv file to / home / user / configured as SESSAO_SSH in PuTTY.

Create a BAT, then just use the Windows Task Scheduler to call the BAT. Set up the session with user and SSH access key , then you do not need a password.

An example of BAT

@echo off

:pscp_path
SET PSCP=ERRO
if EXIST "%ProgramFiles%\PuTTY\pscp.exe" SET PSCP="%ProgramFiles%\PuTTY\pscp.exe" 
if EXIST "%ProgramFiles(x86)%\PuTTY\pscp.exe" SET PSCP="%ProgramFiles(x86)%\PuTTY\pscp.exe" 

if %PSCP% == ERRO goto erro_putty

SET PLINK=ERRO
if EXIST "%ProgramFiles%\PuTTY\plink.exe" SET PLINK="%ProgramFiles%\PuTTY\plink.exe" 
if EXIST "%ProgramFiles(x86)%\PuTTY\plink.exe" SET PLINK="%ProgramFiles(x86)%\PuTTY\plink.exe" 

if %PLINK% == ERRO goto erro_putty

echo "Enviando arquivos de exportação para servidor"
%PSCP% *.txt CentOS_SSH:/opt/dj/djsystem/integracao
move *.txt processado

echo "Chamando execução do script no servidor linux"
%PLINK% CentOS_SSH sh importa.sh

echo "Copiando arquivos de importação para diretório local"
%PSCP% CentOS_SSH:/opt/integracao/*.txt .

echo "Chamando execução do script de remoção dos arquivos"
%PLINK% CentOS_SSH rm -rf /opt/integracao/*.txt

goto fim

:erro_putty
ECHO Putty não conseguiu instalado.

:fim
    
07.08.2015 / 21:09