How to make script for file transfer?

Hi All,

Please suggest me how to make script for file transfer from server X to another server Y.
I have some directory path in server X as below:

/home/directory_1/
.
.
/home/directory_n/

where some text files are available in each directory where some files records zero and some files record is more than zero, now we have to transfer only those files whose record are more than the zero from X server to Y server. Now we need to file in server Y path: /msc/record/dhruva

Please note: X sever means (host name: 133.22.19.11) and Y server means (host name: 130.24.19.11)

You could create a "batch file" containing only the non-zero files on X and then use this to sftp them to Y.

1 Like

Is this to run as a background job or do you just want to run the transfer from the command line. The reason is that if you need to run stuff in the background (without someone at the keyboard to type passwords), you will need to have a method to do password less transfers.

As RudiC points out sftp is a nice tool to transfer files this uses the sshd server on the target machine. If you frequently refresh updated files rsync is another nice tool which compares a directory structure and updates anything new or changed it also uses the sshd server.

I'd start by getting password less ssh working between server X and Y e.g.:

[serverX:/home/directory_1]$ ssh aaditya@serverY id
uuid=1003(aaditya) gid=1000(users) groups=1000(users)

[serverX:/home/directory_1]$
1 Like

I couldn't understand, please elaborate it.

For us to avoid blindly guessing, please post what OS you deploy and which tools you have at your fingertips, like ftp , sftp / scp , rsync , others...

1 Like

Hi RudiC,

We are using sftp

Look at the man page of sftp: It has an option (-b) for providing a batch file with the FTP commands to be executed.

1 Like