Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2012
    Posts
    2

    migrate from FTP to SFTP

    I am using following code for FTP in shell script file and it is working.I want to migrate from FTP to SFTP.What code changes/steps will I have to do for SFTP ?

    FIN

    ftp -in <<FIN
    open $SAP_UP_SERVER
    user $SAP_UP_USER $SAP_UP_PASSWORD
    asc


    put $PM00_OUTPUTS_DIRECTORY/$SAP_UP_FILE_CSV /$SAP_UP_FILE_CSV
    prompt ... End File ftp dates transaction


    quit
    FIN

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,001
    You need some minor changes.
    1 Call sftp with the site and user as command line options:
    Code:
    sftp  -b batch_file $SAP_UP_USER@$SAP_UP_SERVER
    You can set up a passwordless connection, or enter it at the password prompt.

    There is no ascii/binary command.
    There is no prompt command
    batch_file contains
    Code:
    put local_file_name remote_file_name
    quit
    I have never tried:
    Code:
    sftp -b - $user@$site <<FIN
    put file
    quit
    FIN

  3. #3
    Join Date
    Feb 2006
    Posts
    172
    Quote Originally Posted by nivarshn View Post
    I want to migrate from FTP to SFTP.What code changes/steps will I have to do for SFTP?
    This is a example of using SFTP to send(i.e. put) a file in a shell(ksh) script, This assumes you have the appropriate SSH keys setup:
    Code:
    sftp -b /dev/stdin -v -o BatchMode=yes ${v_user}@${v_host} <<ENDSCRIPT
    cd $remote_directory
    put $local_file_path $remote_filename
    quit
    ENDSCRIPT
    rc=$?
    if [[ $rc != 0 ]] then
      print "***Error occurred...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
    else
      print "***Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
    fi

  4. #4
    Join Date
    Dec 2012
    Posts
    2

    Migrate from FTP to SFTP

    I will try below code :
    sftp -b batch_file $SAP_UP_USER@$SAP_UP_SERVER

    batch_file contains
    put local_file_name remote_file_name
    quit

    my shell scripts are executing on unix server and transfering files to window server 2008. will above code work in this scenario ?If yes, then How to set up a passwordless connection ?

  5. #5
    Join Date
    Feb 2006
    Posts
    172
    There are lots of sources for that info on the web, Search on "setup of ssh key pairs", here are a couple of links:
    Setting up SSH public/private keys
    https://help.launchpad.net/YourAccou...ngAnSSHKeyPair

  6. #6
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,001
    You might also consider piping the file through 'unix2dos' prior to sending if you need a file with crlf line endings on the Windows system.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •