I have a few to questions pose in response first:-
What have you tried so far?
What output/errors do you get?
What OS and version are you using?
What are your preferred tools? (C, shell, perl, awk, etc.)
What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
How important is checking file sizes? If sftp fails you get not only trace messages, but a non-zero return code.
We're all here to learn and getting the relevant information will help us all.
I've tried to get file from remote server using sftp in expect script
Just showing the file transferred successfully
RHEL 6.0
preferred shell and awk
It is better to continue the same script that I've shown earlier post
It it important to check file size and check file records remote and local.
if the above is ok then it will compare the file date with file header date.
if ok then change file permission.
Need to mentioned that display error msg is important..
Last edited by rbatte1; 12-02-2014 at 08:30 AM..
Reason: Added LIST=1 tags
Have you heard of exchanging ssh-keys? They will allow you to open an SFTP connection without interaction for a password. It can be to the same user name as your local machine or you can direct them to use a different account on the remote server. It also means that you don't need to store the password anywhere, not even in your script which you then have to stop anyone else reading.
When you get it working, then you can put all the commands you want to issue within a file and use the -b flag of sftp
Errors get a non-zero return code from the sftp so you can be confident your transfer was successful.
I would suggest that you consider RudiC's suggestions too depending on your needs. Don't try to do too much within sftp - it is for transferring data, so use it for that. It you want to have some logic to compare file lists etc. then write that in your shell script and call sftp just for the data transfer bits. You may need to call it more than once to accomplish what you need but with ssh-keys in place it becomes a simple call. You can end up with:-
I hope that this helps,
Robin
Hi All,
I just wanted to write a simple SFTP script.
I already referred to plenty of posts before but its of no use. Please dont give me previous posts link for reference. Please comment if you are really interested in solving my issue.
1. I dont want to install SSH key
2. I dont have... (2 Replies)
Dear All,
I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
hi,
I have a requirement where i need to sftp the file from another server.
Let me describe in detail:
when i login into putty i use my id i.e. kusvi and then i start another acc i.e.cdram where all development works takes place...so if i am in cdram and i need to do sftp i have to exit... (1 Reply)
Hi All,
I'm creating an sftp script that will pull data from sftp server and will also move files to a certain folder.
My question is that how will i know if the moving of files were successful, is there a way for me to determine it.
Thanks,
Reign (1 Reply)
Hi,
I have situation where i need to automate transferring 10000+ files using sftp.
while read line
do
if ; then
echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt
fi
done< files.txt
sftp -b sftpCommand.txt stu@192.168.2.1
The above... (1 Reply)
Hi,
I need a script that automatically connect to a sftp server and send a file. The problem I have is that it need to enter the password. As you might enter the password automatically so it would not ask.
Thank you. (7 Replies)
Hi,
I want download files from Server A to Server B when i want run script.
my source server : A
my Destination server:B
I have to run script in server A only.
please help me on this. (2 Replies)
I am new to the forum. I need help with writing a unix sftp script that will allow me to put a txt file in the destination server. The destination server is a windows box and when I connect from another windows machine, at the dos prompt I need to
Type: ftp<sp> ftp-gw<enter>
Type: servername... (2 Replies)
I have this script but it is not working I need help, to transmit a file and rename it.
#!/bin/ksh
final_file="file name"
ftp -nvd IP_address << ENDFTP
user username password
cd <folder where you want to put the file>
bin
mput $final_file
quit
ENDFTP (0 Replies)
Guys
How can I use sftp through a shell script? OR is there is a more secure way to transfer files from one host to another (in a non-secure environment)?
Please help. I have tried various options. And I am currently doing the transfer of backups manually, I want to automate this.
... (1 Reply)