Sftp transfers file partially

Hi ALL,

I have a shell script using except :

#!/bin/bash
 HOST=abc.com
 USER=abc
 PASSWORD=123
 SOURCE_FILE=file1.zip
 TARGET_DIR=/A/B/C

 /usr/bin/expect <<- EOF

 spawn /usr/bin/sftp $USER@$HOST
 expect "password:"
 send "$PASSWORD\r"
 expect "sftp>"
 send "cd patch1\n"
 expect "sftp>"
 send "pwd\r"
 expect "sftp>"
 send "get $SOURCE_FILE $TARGET_DIR\r"
 expect "sftp>"
 send "bye\r"
EOF

Once I execute the script using it only transfer 20 MB of the file

While if I transfer the file manually the size of file transffered in 80 MB

Therefore the shell script is somehow doesnot wait for send to complete .

Can you all suggest some way to overcome this problem .

Thanks,

You can use rsync to automate file transfer and it works better, in my opinion, than wrapping with expect .

I do a lot of automatic file transfers and I use rsync exclusively. That will solve your problem, moving to rsync .

Hi Neo ,

             rsysnc doesnot work on my system only solution I see is except  

Thanks,

What do you mean "rsync does not work on your system".... what system do you have where "rsync does not work" and why?

Hi ,

It gives me the following error :

rsync /A/B/C/asad

username@server.com:patch/file1.zip
Password:
exec request failed on channel 0
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.2]

That error message indicates you are not using rsync with the correct arguments (paths).

So, it looks like rsync works fine, but you are not using it correctly.

FWIW,

Normally, I pull files from remote servers something like this:

/usr/bin/rsync -qpavzh --rsh="/usr/bin/sshpass -f '/usr/local/rsync/.info' ssh -o StrictHostKeyChecking=no -l username" username@myserver.com:/data/directory_to_sync/ /data/directory_to_sync

How are you using rsync ?

Hi ,

I tried :

/usr/bin/rsync -qpavzh --rsh="/usr/bin/sshpass -f '/usr/local/rsync/.info' ssh -o StrictHostKeyChecking=no -l username" username@myserver.com:/data/directory_to_sync/patch/file1.zip /data/directory_to_sync

1) /usr/bin/sshpass: No such file or directory
2) I need to copy on one zip file like in this case /data/directory_to_sync/patch/file1.zip , I donot want to sync the complete directory .

Yes, that is because you must set up all the right parameters.

You cannot just cut-and-paste my comment / example to you and expect it to work on your server with your userids, passwords, commands and paths.

You must install sshpass, set up your password, paths, etc. Do you not know that? You must read the messages (error messages) and configure your server youself.

I am surprised that you would not know this basic thing about working on a server.

You don't need to do the exact same command as me. I gave you only an example.

You need to learn what you are doing if you are going to be working on a server.

Hey, I have an idea..... maybe you could watch some YT videos on how to set up rsync on a server?

https://www.youtube.com/results?search_query=rsync

Then, you can learn first and ask questions here after you acquire some very basic knowledge.

Thanks

PS: You can user rsync to transfer a single file or an entire website.... but you need to learn these utilities yourself first.

Based on your questions and lack of basic server admin knowledge, I highly recommend you watch some YT video tutorials!

Also, you can enter rsync into the search bar at the top of this page and read myriad discussions on rsync here at unix.com.

I just did, and here are the results:

Cheers.

Hi ,

 I fixed my code :
expect "sftp>"
 set timeout -1
 send "get $SOURCE_FILE $TARGET_DIR\r"

It works fine

There you go ... proving all things are possible if you apply your mind to the situation at hand.

In a parallel world there is a user on unix.com "Asad from India" who is using rsync .... and in another parallel universe the same user got angry and never logged in again.

All things are possible .... :slight_smile: It's up to us.