Migration from FTP to SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Migration from FTP to SFTP
# 1  
Old 07-02-2013
Migration from FTP to SFTP

Hi Everyone,

We are migrating from FTP to SFTP. We used the following script for FTP:

Code:
echo "ftp -np -i -v << EOF" >>  ${FTP_READY_FILE}
echo "open ${SRC_FTP_SERVER} "  >> ${FTP_READY_FILE}
echo "user ${SRC_FTP_USER} ${SRC_FTP_PWD}" >> ${FTP_READY_FILE}
echo "binary" >> ${FTP_READY_FILE}
echo "cd ${FTPDIR} ">> ${FTP_READY_FILE}
echo "lcd ${GETDIR} ">> ${FTP_READY_FILE}
echo "mget ${FileName}*${SRC_OKFILE_XTN_1}" >> ${FTP_READY_FILE}
echo "bye" >> ${FTP_READY_FILE}
echo "EOF" >> ${FTP_READY_FILE}

This code needs to be converted to SFTP code.

The admin people have generated some private and public keys, but I don't know where to place it. Assuming that I have to move files from Server A to Server B, can someone please let me know where to place the keys. Also what changes need to be made to the script to make it work with SFTP?
# 2  
Old 07-02-2013
sftp is not an ftp substitute, it's just ftp-like. Adapting it often means rewriting.

That script looks kind of silly from the get-go, honestly. Why write to a file when you can feed it in directly?

How about:

Code:
sftp username@host <<EOF
cd ${FTPDIR}
lcd ${GETDIR}
mget ${FileName}*${SRC_OKFILE_XTN_1}
bye
EOF

On some systems, you should do sftp -b. If you don't have that option, you're not one of those systems.

Do not indent the last EOF, or the here-document will never end.

What key files do you have?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-03-2013
Hi Corona688,

Many thanks for the quick reply. Yes you are right, the script is kind of silly, but thats how the system was designed in the first place. Smilie So they exported everything in a file, then ran the file.

I am sure that the script that you wrote will definitely solve my problem, but for passwordless authentication we need to keep the public key and private key generated for a user to a particular directory in either Server A or Server B or both. Now I am not sure where the files should be kept (its someting like /.ssh/xxx). Can you please let me know the exact locations where the files should be kept to enable passwordless authentication?
# 4  
Old 07-03-2013
Under $USERNAME/.ssh. Set file permissions to 0600 and directory permissions to 0700.
# 5  
Old 07-03-2013
Quote:
Originally Posted by fpmurphy
Under $USERNAME/.ssh. Set file permissions to 0600 and directory permissions to 0700.
You mean that if I need to move files from Server A (which has the SFTP daemon) to Server B, I need to place the public key in /home/<user>/.ssh/ in Server B?

And what about the private key?
# 6  
Old 07-03-2013
The private key must go on the machine you're running 'sftp username@host' upon. The machine you're logging into, only gets the public key listed in ~/.ssh/authorized_keys.

If you have it, the ideal way would be to just put the keys on the client machine, then 'ssh-copy-id username@host' to copy everything exactly as needed onto the server.

It's difficult to give exact, precise instructions since you didn't tell me what kind of key files you were given when asked(dsa, rsa, other?), just repeated the vague nebulous 'files'... But see passwordless logins with openssh and skip the key-generation steps to see what you need to do.

Last edited by Corona688; 07-03-2013 at 12:17 PM..
These 2 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

AIX - FC Switch migration, SAN Migration question!

I'm New to AIX / VIOS We're doing a FC switch cutover on an ibm device, connected via SAN. How do I tell if one path to my remote disk is lost? (aix lvm) How do I tell when my link is down on my HBA port? Appreciate your help, very much! (4 Replies)
Discussion started by: BG_JrAdmin
4 Replies

2. Shell Programming and Scripting

Sftp equivalent to ftp -n

Hi all. I can put ftp command in shell script together with the password using ftp -n 10.1.2.34 << EOF user userid password cd /test_dir/ prompt bin get filename.txt EOF But the -n option is not available for sftp. What alternatives do I have then to bypass the password prompt? ... (6 Replies)
Discussion started by: aimy
6 Replies

3. Shell Programming and Scripting

FTP and SFTP functionality

Hi Friends, I need to make a Unix script, where i need ftp and sftp functionality. Let me describe in details: I need to import few files from remote server, now these remote server either support ftp or sftp not both. So i need a script where my script will try to do ftp first and if it... (8 Replies)
Discussion started by: gnnsprapa
8 Replies

4. UNIX for Dummies Questions & Answers

Replace FTP with SFTP

Hi All, I am in the process of replacing SFTP instead of FTP to make data more secure. In one of my FTP script I have Quote Site command. I would like to know, what is the option to replace this in SFTP ftp -n -v <<! | tee -a $LOG | grep "Transfer complete" >/dev/null open... (3 Replies)
Discussion started by: desai.vishnu
3 Replies

5. Shell Programming and Scripting

Migrate from FTP to SFTP

Hi,I am using following code for FTP in shell script file and it is working.Now I want to migrate from FTP to SFTP.What code changes/steps I have to perform for SFTP ? ftp -in <<FIN open $SAP_UP_SERVER user $SAP_UP_USER $SAP_UP_PASSWORD asc put... (7 Replies)
Discussion started by: Nitin Varshneya
7 Replies

6. Shell Programming and Scripting

'Upgrading' to sftp from ftp

Somebody made a policy that 'we use sftp now instead of ftp'. I have recommended we use scp because I can't for the life of me think of a *good* reason to use sftp and not scp. But most of what I do is stupid stuff without a good reason. I get judged on how much I can just say yes, no matter how... (1 Reply)
Discussion started by: CodeMonkey76
1 Replies

7. UNIX for Dummies Questions & Answers

FTP / SFTP confusion

Good morning all, I require some help regarding an FTP server i am building. Basically i have around 20 users all sending a receiving files to and from my FTP server but would like all traffic to be secure. I want to ensure users connect via SFTP only and are denied via FTP. Im using... (1 Reply)
Discussion started by: mokachoka
1 Replies

8. UNIX for Dummies Questions & Answers

FTP or SFTP User

Hello there, is there any command in Unix to check that following ftp user is ftp or sftp user. Thanks. (1 Reply)
Discussion started by: ahhmedbilal
1 Replies

9. Solaris

To make ftp an sftp?

Hi All, I want to make ftp for a particular server(ip ,user/passwd) sftp . Regards Megh (2 Replies)
Discussion started by: megh
2 Replies

10. Cybersecurity

FTP v's SFTP

Hi, I'm being told that I have to start using SFTP from my server (HPUX 11i), so heres a few questions; What are the differences between FTP and SFTP? What differences in congiuration can I expect? Are there any changes in command usage? I did see an earlier thread with command issues. A few... (3 Replies)
Discussion started by: nhatch
3 Replies
Login or Register to Ask a Question