If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > migrate from FTP to SFTP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #2 (permalink)  
Old
Programming since 1BC
 
Join Date: Sep 2009
Location: Ontario
Posts: 933
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
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Feb 2006
Posts: 169
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
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
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 ?
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Feb 2006
Posts: 169
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
Reply With Quote
  #6 (permalink)  
Old
Programming since 1BC
 
Join Date: Sep 2009
Location: Ontario
Posts: 933
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On