I want to a transfer file from remote machine to a local machine using SFTP where both my local and remote machines are Ubuntu machines.So i wanted to write a unix bash script which uses SFTP command to transfer the file from remote to local machine.
My remote server is 178.28.30.106.
I'm trying to transfer the file file1 located in the remote machine location "/home/user/datafiles/" to the local machine directory "/home/user/receivedFiles/".
So how to write unix bash script to achieve the file transfer using SFTP?
Can you do this manually first so you can work on automation?
Have you set up SSH keys for passwordless authentication?
Have you used an editor on unix to work on a simple text file?
Most importantly, What have you tried so far?
I don't want to seem aggressive or petty, but I could give you an answer that meets your stated need, but it may either not be quite what you intended and you won't learn how to maintain or support it.
Have a go and let us know where you get stuck and what output/errors you have so we can help.
I have set up the SSH keys for passwordless authentication. Also i tried transferring the file from remote machine to a local machine without writing a unix bash script wich is working fine. I'm able to transfer the file from remote machine to th local machine.
Here initially i moved to the directory where my datafile is residing using
Quote:
cd
and later on did the below code to get the remote file on to local directory
Using unix script , i saw many similar cases where they have used
Quote:
#!/usr/bin/expect
but i wanted to use
Quote:
#!/bin/bash
.
So how to use this and what's the difference between these two?
My bash script is
When i run the above code i'm able to transfer the file from remote to loacl but the problem is nowhere i'm using the password(PASSWD) . So when i run the above script it asks me for the password to enter throught the commandline prompt. So how to avoid this ?
How can i pass PASSWD value so that the human intervension will not be there in transferring the file.
The expect tool is not standard unix. It's freely available, but it#'s a whole language in itself. With SFTP & passwordless keys, you won't need it though.
If you have passwordless authentication, you don't need this bit:-
I presume that you are putting in the real value of user@server and can do this on the command line to get connected.
Can you show us what output do you get manually and then by running your script? Nothing leaps out as a problem at the moment, but if it's prompting for your credentials, then your haven't got passwordless authentication working, which you will need to do first.
Feel free to over-type anything you deem sensitive.
Robin
Last edited by rbatte1; 06-09-2014 at 09:18 AM..
Reason: Comment about being prompted for credentials.
I have updated/edited my reply where I have suggested the issue is with an incomplete setup of SSH key exchange to allow passwordless login. Did you make your client public key trusted on the server account that you want to connect to? What is the server OS by the way?
Can you show us the output from both a manual sftp with the user name you want to connect to and the output from your script.
Hi All,
Need some help regarding file transfer between server.
Suppose we have system-A and system-B. To transfer file from system-A to system-B we usually share the
public keys of system-A to system-B and do scp/sftp to transfer a file.
Is it possible that public key of system-B can be... (3 Replies)
Hi.
I have managed to transfer a file from remote to my raspberry pi, but I have the camera mounted on the Raspbien so I would like to transfer the image the other way.
I use this line:
sshpass -p 'PASSWORD' scp -- USER@ssh.servername.com:/www/cam/image.jpg /home/pi/shared/web/image.jpg (4 Replies)
Hi guys,
Need a quick and urgent help on below issue.
One of our application is try to transfer the file to another host thru sftp process
My file is about 1 GB.
Job is getting hung while transferring the file. So when I login as sftp and check the file system space is only in MB... (2 Replies)
Hello all,
I have a requirement, in which we need to stage a package to Unix remote server in an automation (we cant use ssh key generation) , do u have any idea how we can transfer the package to remote server using sftp .if you have any script plz share it to me (4 Replies)
Hi all,
I'm trying to do a script to transfer file between my server and an external server via SFTP protocol. It doesn't use rsa key, but password.
When I run the script, it throw back a prompt that request me to put the password. How should I do for automatic login? Pleaes help :(
... (2 Replies)
Hello -
I have text file and need to load the data in Oracle through sqlloader.
I need to move this file to unix server and load into oracle. When i SFTP(unfortunately i do not have FTP)
to unix box, each line is appended with ControlM character...
since it is transferring in BINARY... (4 Replies)
I am having trouble viewing a file in ASCII after doing a 'get' using SFTP. It appears to have come across as machine language. Does the file have to be in ASCII format prior to the 'get' or is there a way to convert it to ascii after I get it onto my server? I have read where the secure file... (0 Replies)
hi
i am trying to login to remote server using SFTP Protocol and trying to upload a file butit is asking for the password.
Note: I am trying to connect to FrontEnd server
sftp SFTREGUP1@14.71.26.6
Connecting to 14.71.26.6...
Password Authentication
Password:
Please help (14 Replies)
Hi,
We are facing issue with files transfered using SFTP in Hp-UX.
The transfered files are in Unix Format. That is, file format as UNIX (LF) instead of a PC format (CR & LF).
How can we achieve file transfers as PC format using SFTP?
Your help and input will be highly appreciated.
... (2 Replies)
hi,
I need to sftp a file from one unix system to another unix system.
eg: filename is test.txt
servername : abc@xyz
please give me the sftp command for that.
thanks in advance..
mohan.p (2 Replies)