SFTP

  • Hi to all. I developed an SSIS package to receive a file (specific naming convention *WM.txt), from remote FTP server. The remote file is then deleted. The goal posts have moved at the 11th hour and now I must use SFTP.

    I have installed WinSCP and have created a new connection. I would like to automate getting the file(s) using the configured SFTP WinSCP connection (my_sftp).

    Can any of you coders assist with regards a batch file to call WinSCP to retrieve the required file?

    I have found this site but it doesn't quite do what I require.

    http://blog.skufel.net/2011/12/automating-file-transfer-via-sftp-i-ftps-using-winscp/

    Here is folder structure and script files I created on destination machine (to which files were transferred):

    C:\Apps\WinSCP – folder contains binary files of portable WinSCP application

    C:\Data\Scripts – folder contains batch script to run FTP transfer and script with commands for FTP

    C:\FTP – transfer folder to which files will be transferred from remote site

    C:\Data\Scripts\ftprun.cmd – batch file with command which starts WinSCP with certain parameters

    C:\Data\Scripts\ftpscript.txt – text file which contains commands for WinSCP. It is passed to WinSCP as a parameter by ftprun.cmd script

    I have created a folder C:\sftp

    I have placed portable WinSCP application in sub folder C:\sftp\WinSCP

    I have placed scripts in C:\sftp

    run_sftp.cmd

    C:\sftp\WinSCP\WinSCP.com /script=C:\sftp\sftp.txt

    sftp (this is where I need the help)...I am not looking to synchronize. I want to GET the file *WM.txt file from the remote SFTP site. Save it to local drive C:\SFTP_Get and then delete *WM.txt files from the remote site.

    sftp.txt

    option batch continue

    option confirm off

    open my_sftp

    lcd C:\SFTP_Get

    --synchronize both -delete

    --synchronize both C:\FTP /

    exit

    I would appreciate any help.

    Kind Regards,

    Phil.

    -------------------------------------------------------------------------------------
    A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

    Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

    Tommy Cooper

  • It would appear this works.

    option batch continue

    option confirm off

    open my_sftp

    lcd C:\SFTP_Get

    get *WM.txt -delete

    exit

    Now to test it as a scheduled task.

    Phil.

    -------------------------------------------------------------------------------------
    A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

    Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

    Tommy Cooper

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply