Creating Schedule to transfer CSV files from Winscp to FTP

Asked

Viewed 1,299 times

1

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

I found that link that involves creating and using Schedules using Winscp, but got me a little vague.

What could I do in this case?

1 answer

0

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

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

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

Create a BAT, then just use the Windows task scheduler to call the BAT. Configure the user session and SSH access key, ai need no 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.