Sftp,[put] all files that are .csv to server. Linux Ubuntu


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Sftp,[put] all files that are .csv to server. Linux Ubuntu
# 1  
Old 02-19-2018
Display Sftp,[put] all files that are .csv to server. Linux Ubuntu

Hello all,

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".

Code:
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;

Code:
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.Smilie

Last edited by vbe; 02-19-2018 at 02:59 PM.. Reason: code tags please for the code, not icode, thanks
# 2  
Old 02-19-2018
Hey,
have you checked the permissions of the identity file?
can you post the complete contents of the file, instead of bits and pieces?
# 3  
Old 02-19-2018
Is it possible that you have a "-0" (zero) in lieu of the -o option? And, the here document's redirection points the wrong direction.

Last edited by RudiC; 02-19-2018 at 06:48 PM..
# 4  
Old 02-20-2018
Display My full script

Thanks for your replies, I have checked the permission on the key folder. It has chmod 700.

Here is the cron job that runs the code:

Code:
01 17 * * * /etc/cron.daily/Transfer.sh 2>&1 | etc/cron.daily/TimeStamp.sh >> /home/usert/Transferlogfile.log

Here is the full script:

Code:
#!/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:

Code:
#!/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?

Again, thank you for your time and answers


Moderator's Comments:
Mod Comment Thanks for trying, but: Please use CODE (not ICODE) tags as required by forum rules!

Last edited by RudiC; 02-20-2018 at 08:09 AM.. Reason: Changed ICODE to CODE tags.
# 5  
Old 02-20-2018
What Linux distribution are you using?

Let's break up your script.

Code:
#!/bin/bash -x

Code:
sftp -oIdentityFile=~/.ssh/id_rsa/sftp -v username@192.168.17.181<<EOF

The above statement worked fine.

Code:
cd ../../

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"

Code:
put ftpusers/TransferFolder/ftp/data/*

try using absolute path starting from "/" example "/home/user/ftpusers/TransferFolder/ftp/data/*"

Code:
echo "File transfer has been completed"

echo will not work inside FTP, need to use after EOF.

Code:
bye
EOF

This looks good

Also please see below a version of script that worked for me.

Code:
#!/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.

hope this helps.


Moderator's Comments:
Mod Comment Please use CODE (not HTML) tags as required by forum rules!

Last edited by RudiC; 02-20-2018 at 03:31 PM.. Reason: Changed HTML to CODE tags.
# 6  
Old 02-23-2018
Display

Hi,
Thank you for your reply, I was confusing the cd and lcd which when corrected now functions.
Thanks for all your help.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

How to Build an Email Server on Ubuntu Linux?

hi there ! how SSH into my Ubuntu server to Build or Send an Email? is it true to use iRedMail? (1 Reply)
Discussion started by: fns4565
1 Replies

2. Linux

SFTP files to a server from Linux.

Hi, I am looking for a shell script to sftp to a file server and copy all the files from a directory after the script is run. The server name should be a user input parameter and of-course the username/password as well. Rest all should be handled by the script. I tried with below snippet:- ... (1 Reply)
Discussion started by: happysingh
1 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

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

5. 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

6. 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

7. Emergency UNIX and Linux Support

Help with Ubuntu Linux Server Password Problem...

Hi all, I have no root access enabled on our linux server due to safety issues. We use sudo. When I change my password using passwd command, I sometimes get issues where I can't log back in. Pam_Tally disables due to trying my password too many times. So someone in my group has to reset... (7 Replies)
Discussion started by: zixzix01
7 Replies

8. Shell Programming and Scripting

Combine two files and put it in .csv file

Hi Freinds I have two .txt file gem1.txt and gem2.txt, Sample gem1.txt abstract (1.0.0) actionmailer (2.3.5, 2.2.2) actionpack (2.3.5, 2.2.2) activerecord (2.3.5, 2.2.2) activerecord-oracle_enhanced-adapter (1.1.9) activerecord-sqlserver-adapter (2.3.4) activeresource (2.3.5, 2.2.2)... (3 Replies)
Discussion started by: ankit_view24
3 Replies

9. 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

10. UNIX and Linux Applications

sftp -> put : How to uplaod only newer files

I have tried winscp, filezilla to copy data from windows xp SP2 machine to the sun sparc unix machine. However speed is around 120 to 130 kb/sec. I do have lot of files & with large size. So I switched to windows command prompt & transfered few files using sftp command. Its very fast as compared... (0 Replies)
Discussion started by: _prasad
0 Replies
Login or Register to Ask a Question