Changing from FTP to SFTP server


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Changing from FTP to SFTP server
# 1  
Old 07-10-2013
Tools Changing from FTP to SFTP server

Hi everyone, I am having problems with changing a script (originally it is used to transfer file from an FTP server to another place). Now the company change the FTP to SFTP server, so I need to change the script accordingly.

Basically, I have trouble with the log in authentication, here is the old log in part:
Code:
    echo "INFO    :    Generating FTP file size logging script" >> $log
    echo "ftp -n << FTPEND"           > $ftpProxy
    echo "open ${ftpServer}"         >> $ftpProxy
    echo "user $username $password " >> $ftpProxy
    echo "cd $ftpSourceDir"          >> $ftpProxy
    echo "ls -l ${tmpFile}.filesize" >> $ftpProxy
    echo "close"  >> $ftpProxy
    echo "bye"    >> $ftpProxy
    echo "FTPEND" >> $ftpProxy
    chmod 774 $ftpProxy
    $ftpProxy > ${tmpFile}

The generating log in file is in the same file as the rest

Now, when I look online for sftp log in credential, it seems that I need a separate log in file and an cmd file to do other thing, here is the sample:

Code:
spawn sftp -b [cmdFile] [username]@[servername]
expect "password:"
send "[yourPassword]\n";
interact

The point is if I generate out a log in file like that (which needs a cmdFile tp run) then I will not have the cmdFile at that time since the code gor the other part is generated after the login part (in the original file)

I know this maybe very confusing (since I am also quite confused with this whole ftp - sftp thing), I hope you guys can help me out a bit. Many thanks

Oh, one last thing, just asking: regarding commands, is there any difference between sftp and ftp Smilie
# 2  
Old 07-10-2013
The syntax should be about the same for sftp, but the authentication works different, as you already noticed. You can't supply user and pw this way. Either your exchange ssh-keys (there is plenty of topics about this for "passwordless ssh" here in the forums as well on the www) or supply it manually, where the latter you don't want to. You can automate it also using expect to feed the credentials. There should b also some posts here in the forum about it you can find, using the search function.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 07-10-2013
To expand on what zaxxon explained:

With "ftp" you:
  • connect to the other server
  • are asked for a username
  • supply this
  • are asked for a password
  • supply this
  • send one (or some) commands as now authenticated user
  • close the connection

With "sftp" you:

exchange ssh-keys instead of user/password before you even attempt to transfer files. You do this only once. The "session" itself is:
  • connect to the other server
  • system automatically supplies the authenticating key
  • send one (or some) commands as now authenticated user
  • close the connection

The advantage is: you do not have to put passwords in clear text into scripts. Instead you exchange a secret (keys) once and then use these automatically. These secrets are not being sent in clear text over the network either (unlike "ftp", where passwords are transferred that way), which further enhances security: nobody listening on the network can collect the secret and then use it himself.

Things you have to consider: if you have a firewall between the two systems make sure you have the necessary ports opened. "sftp" operates (usually - can be configured) on another port than "ftp" (usually) does.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 4  
Old 07-10-2013
HI, thanks for your help, I know there are posts out there talking about ssh key, but I hope you guys can help me again, so now I have the username and password for the SFTP server. Will I have to somehow generate this username and password into a ssh key; or I can create a separate ssh key (separate from my existing user name and password).
If there is any sample code for such procedure, I would be really appreciate, thanks Smilie
# 5  
Old 07-10-2013
Quote:
Originally Posted by warmboy610
Will I have to somehow generate this username and password into a ssh key; or I can create a separate ssh key (separate from my existing user name and password).
This actually is discussed in the man page of "ssh" at length. I suggest you read this.

Suppose you are userA@hostA and want o connect to hostB as userB:
Basically, you connect to the remote system once using standard username/password authentication. Then you generate an ssh-key on this remote system as the authenticated user. Transfer this generated key (this is a long string, you can either put it into a text file and transfer this, but even copy&paste would work) to the machine you connected from. There you have a "keyring" file ("hostA/~userA/.ssh/authorized_keys"), where you simply append this string. From now on, when you attempt to connect to hostB as userB coming from hostA as userA the ssh (or sftp) software provides this key and the remote system - instead of asking a password - takes this as authentication.

Note that this will not work both ways: the above would only provide passwordless access as userA@hostA to userB@hostB. To connect to hostA as userA coming from hostB as userB you would have to generate another key and transfer it in the other direction first.

Note also that this only authenticates a single host/user pair: If userA@hostA can connect passwordless to hostB as userB this neither means that userB@hostA can do the same or that userA@hostA can connect as userA@hostB without a password. You would have to generate and exchange keys first as these user/host combinations to make it work.

Another thing: generate keys only ONCE. If you want to connect as userB@hostB coming from userA@hostA as well as userB@hostA then connect to hostB as userB first, generate the key and put this key into the keyring file of userA@hostA as well as userB@hostA. Do NOT generate 2 keys!

I hope this helps.

bakunin

Last edited by bakunin; 07-10-2013 at 07:32 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to ftp or sftp from workplace to UNIX server?

Hi All, Seeking for your assistance on how to ftp or sftp from workplace to unix server? i tried ftp user/pass but it says "command not found" i tried sftp user@localhost i can't connect. Please advise, Thanks, (1 Reply)
Discussion started by: znesotomayor
1 Replies

2. Shell Programming and Scripting

Needed SFTP script from windows to UNIX server and from UNIX to windows server(reverse SFTP)

hi guys, i need a script to sftp the file from windows to unix server ....(before that i have to check whether the file exists in the windows server or not and again i have to reverse sftp the files from unix to windows server..... regards, Vasa Saikumar. (13 Replies)
Discussion started by: hemanthsaikumar
13 Replies

3. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

4. Shell Programming and Scripting

Sftp script for dev server to client server

hi, i am new to unix, cuold u send some sftp acripts to send files to dev server to clint server, (1 Reply)
Discussion started by: Koti.annam
1 Replies

5. Red Hat

Implement FTP server on RHEL server without using FTP client

We have RHEL 5.8 in our environment, I had a query whether we can implement an FTP server using vsftpd package and Linux configurations like setsebool without using any external FTP clients like FileZilla etc. I am very confused on this. The FTP functionalities that should be present are download &... (3 Replies)
Discussion started by: RHCE
3 Replies

6. IP Networking

How to transfer files from UNIX server to windows machine or vice versa using ftp or sftp commands?

hi, i want to write a shell script code which transfers files from a directory in unix server to a directory in a windows machine.. can any1 give me a sample code which uses ftp or sftp command.. thanks very much, (3 Replies)
Discussion started by: Little
3 Replies

7. Shell Programming and Scripting

Sftp some files from windows server to UNIX server

hi i need to transfer some files from windows server to unix server using SFTP. but before transferring the files, i need to check the existence of a particular file in the remote directory (say r_dir1). if the file is present, then SFTP all the files. after SFTPing the files from the remote... (1 Reply)
Discussion started by: vinit raj
1 Replies

8. Shell Programming and Scripting

Transfer files from linux server to windows using secure ftp (sftp)

HI, I have to transfer files from linux server to windows using secure ftp (sftp) .Kindly help me out. (3 Replies)
Discussion started by: manushi88
3 Replies

9. Shell Programming and Scripting

Using SFTP and FTP to transfer data from One Remote Server To Another

HI I need to write a script in 415univ server which should go to 534unix server and move the files from there to windows server. I am not able to get it bcoz sftp prompt is not allowing ftp command. Can some one plz help me Thanks in advance (3 Replies)
Discussion started by: himakiran9
3 Replies

10. Emergency UNIX and Linux Support

solaris or linux sftp/ftp-server

Hi, we have a big problem, history: we migrated our companies ftp and sftp-server, which were vsftp and openssh, to one server, software is called JSCAPE ftp server professional edition for the first time everything was great, but after one or two months, our uploads hang, 0 byte files are... (11 Replies)
Discussion started by: funksen
11 Replies
Login or Register to Ask a Question