I am trying to sftp files to a server, I am using keys as authentication and I can connect with no problems. I can also put a sample file on the server.
When I tried to automate this process with a .sh file I get the "couldn't canonicalize: Failure".
This is my script: sftp -P22 -0IdentityFile=~/.ssh/is_rda/sftpKey sftp@ipAddressHere -v >>EOF
This shows that i connected with the -v debug and all keys are working.
My code to put the files then looks like this;
cd /./.
put *.csv*
echo "File has been sent"
EOF
my files have been given the chmod
I am trying to put all files that have a .csv on the server.
What am I doing wrong?
Many thanks for any help you provide.
This is my first post so I hope I have been descriptive enough.
#!/bin/bash -x
sftp -P 22 -oIdentityFile=~/.ssh/id_rsa/sftp -v username@192.168.17.181<<EOF
cd ../../
put ftpusers/TransferFolder/ftp/data/*
echo "File transfer has been completed"
bye
EOF
Using the same sftp line from my script connects to the server because debug shows the key verification process and says connected.
Basically, I need a script that will send any file with the .csv extension that is in the data folder, to the server each day at just after 5.
I also have another script which you can see referenced in the cronjob which is to create a log file with the date of transfer and file name sent, here that is:
#!/bin/bash
while read x; do
echo -n `date +%d/%m/%Y\ %H:%M:%S`;
echo -n " ";
echo $x;
done
The path ftpusers/TransferFolder/ftp/data/ is 2 folder levels below my users home path, e.g ~/. So I need to ../../ to then go to my ftpusers/TransferFolder/ftp/data/ ,path. will this affect the process?
are you trying to change directory in your local machine or your remote machine?
if you are changing in remote "cd" will work.
if you are trying to change locally, try "lcd"
put ftpusers/TransferFolder/ftp/data/*
try using absolute path starting from "/" example "/home/user/ftpusers/TransferFolder/ftp/data/*"
echo "File transfer has been completed"
echo will not work inside FTP, need to use after EOF.
bye
EOF
This looks good
Also please see below a version of script that worked for me.
#!/bin/bash -x
sftp -o IdentityFile=~/.ssh/sftp -v remote_user@remote_machine<<EOF
cd files
put /home/localuser/files/*
bye
EOF
[[ ${?} -eq 0 ]] && { echo "File transfer has been completed"; } || { echo "File transfer Failed"; }
The above script transfers all the files from dir "/home/localuser/files/" on the local machine to
"/home/remote_user/files" directory on the remote machine.