Problem automating sFTP transfer using script in cron
Hi Newbie here
I am having problems with automating sFTP transfers.
Just to save time - SCP is not an option as sFTP is stipulated by controllers of far end server.
Ineed to automate sFTP transfer of a single file, once a day to a remote server to which i have no control over.
I am using: Solaris server (Solaris 9 9/05 s9s_u8wos_05 SPARC), the UNIX provided OpenSSH, SHELL=/bin/sh
So far i have mangaged to set up the required DSA keys and connected to the server manually using sFTP without having to enter a password(so i know the keys are working ok) and manually put a test file on there.
My next task and the bit i am stuck on is to write a script to automate the daily file upload - same filename every day and simple overwrite.
Problem is that all posts i have currently seen suggest to use -b option and write sFTP in separate file, sFTP reports that -b is an illegal option so need to write a script that will initiate the connection, pass the sFTP commands required and then close the connection so that i can put it in the crontab for running once a day.
This is a here document. Is this what you are asking? Or is it something to do with cron? 11.22.1.2 is the remote host name or ip address. cron has to run under the crontab for the user with the keys.
Hi
Thanks for the reply.
It's not a cron problem - i haven't got as far as putting in the cron yet.
I can manually connect:
sftp username@host
this automatically connects me as i have already set up the keys.
I can then transfer file: put file
Then disconnect: exit
That is all that is required except for the fact i want to do is automatically via a script so it can go in the cron - just dont know how to get the sftp commands to be read and get the connection to exit without doing it manually
Cheers
It's been done. It's designed to. The trick to scripting a login is to use a non-interactive login method, like keys.
Quote:
I had to use expect to "automate" it.
The script you've quoted has a security hole big enough to drop a cow through. Passing a password through commandline parameters lets anyone logged into the system see it, in plaintext!
This is why things like scp, sftp, ssh, sudo, and su won't accept passwords through anything but a terminal. It's a subtle hint, written in mile-high flashing neon letters: This is a bad idea. You're not supposed to do this. By using expect to brute-force it into running the wrong way, you've learned the wrong lesson.
Doubly so, since the OP has already said they already have working passwordless logins, arranged the proper way: keys. Logging in is not the problem here. Please think next time before you suggest brute-forcing passwords insecurely.
---------- Post updated at 01:34 PM ---------- Previous update was at 01:28 PM ----------
Quote:
Originally Posted by robbien
That is all that is required except for the fact i want to do is automatically via a script so it can go in the cron - just dont know how to get the sftp commands to be read and get the connection to exit without doing it manually
Cheers
This works fine for me when passwordless login's arranged:
It logs in, does ls, and quits. You can have as many lines of commands as you want, just add them:
Hi All,
I am having an issue with the script execution. I am having a SFTP process that send files to a location . I want to execute a script once it transfer the file to that location. Right now I am leveraging autosys file watcher to do that. Is there any way like MFT PPA that can execute... (2 Replies)
Hello,
Recently I have changed some crontab scripts which I execute to do different tasks mainly transfering some files from one server to the other.
The main change was the protocol from ftp transfer to sftp. Ftp server was the MS Windows default service, and Sftp server is an proprietary sw... (4 Replies)
Hello gurus,
I am making what I think is a simple db2 call from within a shell script but I am having difficulty producing the desired
report when I run the script shown below from a shell script in cron. For example, my script and the crontab file setup
is shown below:
#!/bin/ksh
db2... (3 Replies)
I had the below sftp script working perfectly but the problem is I am not able to send the echo statements .
#!/bin/sh
echo "Starting to sftp..."
sftp admin@myip << END_SCRIPT
cd /remotepath/
lcd /localpath/
mget myfiles*.csv
bye
END_SCRIPT
echo "Sftp successfully."
echo
echo... (11 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)
Hi Experts,
Few more words to the title, both the servers are ssh enabled but I have read only access to the second server, so I cannot automate SFTP process using RSA/DSA keys.
I am using Control M to trigger the script and do not want any manual intervention to enter the password to complete... (4 Replies)
Hi
We are trying to set up a non-interactive sftp to one of our clients to be able to transfer files to them. For the setup I logged into server1 as user1 and generated RSA public and private keys id_rsa and id_rsa.pub. Then I did an sftp to server2 as user2 and put the id_rsa.pub in the .ssh... (4 Replies)
Hi all.
basically i need to run a script every 30 minutes.
my script is simply an error report:
errpt
thats it, is there anyway to make this happen every 30 minutes
without having to type errpt in, the script will get bigger as i add more things to do but just need to know how to... (8 Replies)
I have written generic script to transfer files from one machine to other machine(By passing the command line arguments like server name, user name ,location of the files, file names etc) but
when i am using sftp, what are the things I have to specify in the code
Is it necessary to specify... (0 Replies)
I have to write an automated sftp script which uses password authentication method to access the remote server. I want to pass the password as a parameter or to be included in the script itself, so that when i run the sftp script, it should not prompt me to enter the password.
Thanks in advance... (1 Reply)