Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Sftp,[put] all files that are .csv to server. Linux Ubuntu Post 303013373 by Kesavan on Tuesday 20th of February 2018 12:30:09 PM
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 02:31 PM.. Reason: Changed HTML to CODE tags.
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 03:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy