Need the sample code for implementation of SFTP


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications Need the sample code for implementation of SFTP
# 1  
Old 08-14-2008
Need the sample code for implementation of SFTP

Hi
we need to implement SFTP through unix shell scripts. I have seen many posts, in which there is discussion about non-interactive,automated SFTP.
Can anyone please send me the sample code for SFTP shell script. We are using SFTP to transfer the files from the host server to the target server.
# 2  
Old 08-14-2008
There are plenty of possibilities, you can create quite large matrix with options, let us know more about your specs : OS, users ( got root ?), language, uploads, downloads. Actually, if you have clear requirements and little bit more patience to search in the forum, you will find many different solutions.
# 3  
Old 08-18-2008
We are looking to run an SFTP Shell Script, from a server A(Database Server), to be able to transfer files from a server B(Application) to the Destination Server C.

Basically we need to SFTP a file from one server to another, with the script running on a third server.

Any assistance with this would be great.Sample codes would be of great help.

Thanks

Madhu
# 4  
Old 08-18-2008
All servers are UNIX based.
# 5  
Old 08-18-2008
I see, well, in my opinion TCL/expect based code will be a good choice. Sample code :
Code:
#!/usr/bin/expect

set timeout -1

spawn sftp -oPort=22 $user@$host
expect *assword:
send "$pass\r"
expect sftp>
send "put file1 newFileName\r"
expect sftp>
send "exit\r"
expect eof

The above will connect to a host, and will transfer a file via SFTP. Modify per your needs. Note - you can also use autoexpect, which will record your actions and will generate the script.
# 6  
Old 09-03-2008
I am attempting to do the same with a script. The Sun Sparc9 Server I maintain does not have the expect command located on the hard drive. Is there another command that works the same?
This is a govt. Server, so downloading files to it is not an option.
# 7  
Old 09-03-2008
wsiefkas,

You can use ssh's pki (keys) to facilitate interaction from a shell script. Simply look at the man pages for : ssh-add, ssh, ssh-agent, ssh-keygen, sshd, etc.. for details. This does
add to administrative overhead (key-management and key maintenance) in a way that an expect based solution avoids.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sample output

hi gurus , i want the command to get the output in the desired format . basically to convert columns to rows. please refer to the attachment. (3 Replies)
Discussion started by: r_t_1601
3 Replies

2. UNIX for Dummies Questions & Answers

Finding implementation code in UNIX for FAT16/32

So we know that Unix is free source software. And we know that Unix have support for FAT 16 and FAT 32. Does anyone know where can I found that implementation in code ? Thank you. (2 Replies)
Discussion started by: medolina
2 Replies

3. Shell Programming and Scripting

sample code to display mounted devices

Hi all I need to write shell script to list out the mounted devices for a particular user. As i am new to shell script please help me. Here the problem is sometime unmounted devices also will be displayed in fstab. How to rectify that? Can anybody help me? Regards Ilamathi (0 Replies)
Discussion started by: ilamathi
0 Replies

4. Shell Programming and Scripting

SFTP return Error Code 126

Hi, We are getting the following error code while connection remote server using sftp command. sftp user@serrver Warning: child process (/opt/ssh2/bin/ssh2) exited with code 126. pls Advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

5. UNIX for Advanced & Expert Users

SFTP was successfull but got return code as 1

Hi, I am using SFTP for transferring files to remote server. Below is the snipped i am using for my sftp program echo "lcd $i_localdir">/tmp/sftp_Batch echo "cd $i_destdir">>/tmp/sftp_Batch echo "put $i_filename">>/tmp/sftp_Batch echo "chmod 644... (2 Replies)
Discussion started by: Ankgne
2 Replies

6. Solaris

Java api/sample code for sftp

I'm trying to find an api for Java to send/receive files via sftp. There are some available for purchase out there such as JScape, but I was hoping to find a free one. Does anyone know of one? I would also like to find an open source java example application that can send files via sftp. ... (2 Replies)
Discussion started by: JohnRodey
2 Replies

7. Programming

Help need a sample program

Hi all, Can some one provide me a sample program which measures the performance (both latency and throughput) of TCP and UDP protocol (2 Replies)
Discussion started by: magnetpest2k7
2 Replies

8. Shell Programming and Scripting

Can't use Text::CSV... any sample code out there?

I was looking at a library that lets me parse comma delimited csv files without a problem, but unfortunately, I'm not allowed to make use of that library. I understand that the library probably does something similar to a string split(), but I don't quite know what kind of regular expression is... (1 Reply)
Discussion started by: mrwatkin
1 Replies

9. Programming

C code for implementation of Memory Mapping

Please post a C code for implementation of Memory Mapping function. It should simulate the mmap command. (1 Reply)
Discussion started by: raviviolet13
1 Replies
Login or Register to Ask a Question